microsoft / RulesEngine

A Json based Rules Engine with extensive Dynamic expression support
https://microsoft.github.io/RulesEngine/
MIT License
3.59k stars 540 forks source link

Performance issue with rule-chaining #471

Open jchen-chc opened 1 year ago

jchen-chc commented 1 year ago

We have a large number of rules to run. We tried to use rule-chaining to improve performance by short-circuiting when a rule succeeds.

However, our benchmark tests showed that rule-chaining is much slower than ExecuteAllRulesAsync scheme.

The source code of ExecuteActionWorkflowAsync indicates that it makes a copy of the RuleResultTree for each rule executed in the chain.

Can someone look into this performance issue and possibly make a fix soon?

Thanks

abbasc52 commented 1 year ago

@jchen-chc can you share the number of rules and the performance numbers?

jchen-chc commented 1 year ago

We had a benchmark with 10K run. We chained rules with OnFailure event. Here are some test results: 10 rules in the chain, 1st rule succeeds. the mean time is: 46.92 ms 10 rules in the chain, 2nd rule succeeds. the mean time is: 539.8 ms 10 rules in the chain, 3nd rule succeeds. the mean time is: 1.664 s

As a comparison, executing the 10 rules without chaining, the mean time is: 109.0 ms

MithunChopda commented 1 year ago

Is anyone looking into this? I am in a similar situation where I need to run 15 - 20 conditions (mostly equality operators) for a dataset of 600 records. This takes 15 seconds to complete. This is very slow. I am unsure if this is something that requires a fix or something that cannot be fixed. I can make a decision accordingly.