Fork me on GitHub

Can you put a time on each rule? Or a route to view the profile/debug the rules? There is something slow in my engine but I'm not sure how to find what it is.


maybe run your engine under a profiler like VisualVM? can see what methods may be using the most time and go from there?


If the problem is a function in your rules (RHS, accumulator function, etc.) that’s taking a lot of time then something like VisualVM would likely be helpful. That’s where I’d start. If the problem is that the rules are firing in a bad/suboptimal way then Clara’s tracing could provide some info, but that is harder to use., the discussion on around potential tracing enhancements could give some insight into how it works as well


@wparker I made a macro that wrap rhs inside a time-like macro, that time RHS and store it's time on a global atom (just for use on repl). It allow's me to see how many times each rule is fired, how many time each "burn" takes, avg, "total time" from each rule. Simple and usefull 😄


(now I'm using my-ns/defrule in place of clara.rules/defrule)


Glad you’ve found a working solution @souenzzo FYI, there are some cases where Clara could repeatedly add a rule to the queue of things waiting to be fired, remove it, add it again, etc. without ever actually firing it (and thus avoiding that macro) but my guess is those cases are a small though nontrivial minority of perf problems


@wparker I'm just trying to find any slow rhs. Insert or not insert, use or not, not matters. I find a single rule that takes 100x more time that any other. I think that not matter if it will be used or not, in this case.


Excellent, sounds like you’ve found your performance problem. 👍


so that sounds like it would work most of the time