New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rule session factory compilation can take a long time #191
Comments
Some more details. The app is loading about 400 rules, with about half of rules using Or clauses, some with 10+ clauses within ORs. Since OR'd rules are effectively like adding additional rules, it's probably close to 750 rules equivalent. |
Collapse multiple expression classes into a few generic ones; unify the code. Compare expressions for node sharing prior to compilation, thereby improving compilation performance in those cases where there is node sharing. Eliminate some unnecessary allocations during rule compilation (should help with #191 ).
I am experiencing the same issue. It takes about five minutes to compile. I have 1200 rules. |
As an option, consider https://github.com/NRules/NRules/wiki/Expression-Compiler to hook up FastExpressionCompiler that will improve the compilation performance. |
@larryPlayabl @fkucuk Did someone actually tried FastExpressionCompiler and what was the performance? |
I tried the FastExpressionCompiler and this indeed did speed up the process. |
@dadhi I did try it and it sped up compilation a bit. @kk738 Isn't compilation a one-time hit though? So even if it's a bit slow, you can continue to use the compiled factory once you have it, and spinning up new sessions from the compiled factory is very quick. Is there a reason you're compiling more than once? |
@larryPlayabl What kind of expression are those? |
Thanks for that hint, I simply didn't consider this. So I simply misused the lib, because of the way my application used to work before. |
@dadhi Sorry, what do you mean by kind of expression. The C# class type of the expression, or are they categorized in some other way? |
@larryPlayabl I mean the example of expression in use. |
@dadhi I just realized that you are the owner of the FEC project and so that's why you were asking about the types of expressions others are trying to compile. TBH I personally haven't had a ton of issues with the compilation performance, even using the built-in .net compiler, but clearly, it's more painful for some folks. @kk738 it was already pointed out by @larryPlayabl that normally, you would expect compilation to only happen once, at the application startup, and then you just keep |
We're using NRules in an interactive realtime application that needs to compile the rule factory on application start. We're starting to notice that our rule factory compilation is taking a long time. (10 seconds and growing so far on my PC, and about 40 seconds on the low power device we'll eventually be supporting.)
Specifically, this time is spent in RuleRepositoryExtensions.Compile() method.
Doing some initial profiling, the bulk of the time spent seems to be in RuleElementVisitor`1.Visit().
Drilling into this a bit, at first glance I see the bulk of the time spent in ExpressionComparer and LambdaCompiler methods.
A few screenshots of profiling are attached in case this is helpful.
The text was updated successfully, but these errors were encountered: