question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule session factory compilation can take a long time

See original GitHub issue

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. Screen Shot 2019-06-26 at 10 12 48 PM Screen Shot 2019-06-26 at 10 11 36 PM Screen Shot 2019-06-26 at 10 10 28 PM Screen Shot 2019-06-26 at 10 09 44 PM

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
snikolayevcommented, Mar 24, 2023

@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. @larryPlayabl @kk738 I think this is a chance for you to share the types of expressions (types of expression nodes used) that you see causing the biggest impact on compilation performance, which could help @dadhi improve FEC performance, making everyone benefit from it. Also, if I’m not mistaken, FEC can fallback to .NET native expression compiler if it’s unable to handle some expression, which is another reason why you may not be seeing as dramatic a benefit as you might have expected. So, finding these cases where the fallback occurs, and reporting those to FEC project will also potentially benefit everyone.

@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 ISessionFactory around and don’t really count rule compilation towards rules evaluation time. I find your idea of precompiling expressions interesting (and it has been raised before), so I might explore it. I was intrigued by the introduction of source generators in . NET, so perhaps that’s an option worth exploring. Regarding your point on using delegates instead of expressions in NRules - not possible, as delegates are opaque, and the engine needs to rewrite and stitch the expressions together to make it work in cases where expressions depend on other expressions.

1reaction
snikolayevcommented, Jun 29, 2021

As an option, consider https://github.com/NRules/NRules/wiki/Expression-Compiler to hook up FastExpressionCompiler that will improve the compilation performance.

Read more comments on GitHub >

github_iconTop Results From Across the Web

sessionfactory creation takes a lot of time to load for the first ...
While loading up the application for the first time the session factory takes a lot of time to load (around 3-4 minutes), but...
Read more >
Session (Hibernate JavaDocs)
A Session instance is serializable if its persistent classes are serializable. A typical transaction should use the following idiom: Session sess = factory....
Read more >
Chapter 3. SessionFactory Configuration
Configuration represents an entire set of mappings of an application's Java types to a SQL database. The Configuration is used to build a...
Read more >
HibernateSessionFactory
SessionFactory ; import net.sf.hibernate. ... Configuration config = new Configuration() { /* Make sure, we use the current Classloader for ...
Read more >
Hibernate - Criteria Queries
The Hibernate Session interface provides createCriteria() method, which can be used to create a Criteria object that returns instances of the persistence ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found