oracle-samples/clara-rules

Add node ID and/or rule name info to compiled RHS action functions

Closed this issue · 1 comments

Compile-action creates unevaluated code for an anonymous function that executes the RHS of a rule. Since the current namespace is bound to the namespace from which the rule came when this code is evaluated the class of the evaluated function will reflect this namespace. However, the class won't indicate which rule this came from, which would be helpful in profiling. Demonstration:

(in-ns 'clojure.core)
clojure.core=> (def fn1 (eval `(fn [~'x] (+ ~'x 1))))
#'clojure.core/fn1
clojure.core=> (def fn2 (eval `(fn meaningful-name [~'x] (+ ~'x 1))))
#'clojure.core/fn2
clojure.core=> (class fn1)
clojure.core$eval10594$fn__10595
clojure.core=> (class fn2)
clojure.core$eval10598$meaningful_name__10599

Since the node-id is available and compile-action is only called in ProductionNode compilation we can just give the anonymous function a name like "production-rhs-(NODE_ID_HERE)", something similar involving the name, or a combination of both.

The benefit of this change would be that it would be easy to tell from profiling e.g. in VisualVM what rule these functions correspond to. I just had a case where one of these functions showed up as a hotspot.

This is similar to #261 but I think that issue is more for the alpha node activations, for which this fix is blocked by #237, whereas for production RHS actions there isn't anything blocking the change.

I think this was addressed by https://github.com/cerner/clara-rules/pull/451/files so I'm going to close it for now but feel free to reopen it if there is more that you want to address here @EthanEChristian .