FrederikVds
FrederikVds

Reputation: 558

Profiling constraint streams score calculation in Optaplanner

I'm looking at profiling the score calculation in my Optaplanner project to find out if there are any hotspots that would benefit from being optimised. However, visualvm shows most of the time to be taken in the self time of org.drools.modelcompiler.constraints.ConstraintEvaluator$InnerEvaluator$_2.evaluate. I therefore assume that this method is what actually runs a lot of the constraint's code. What is the best way to find out what specific pieces of code are taking the most time?

Upvotes: 1

Views: 188

Answers (1)

The thing to understand about Constraint Streams is that it is not imperative programming, and therefore traditional performance optimization techniques such as code profiling are not going to be very helpful. Instead, I suggest you think of Constraint Streams as SQL - the way to have fast SQL is to think about how your data flows, how you join and what gets indexed.

Recently I wrote a blog post explaining the tricks behind making CS run fast. However, CS is internally interpreted by the Drools engine, and therefore studying it may give you some insights too. Not all insights there are applicable to CS, but if you take a look at drools-metric, you should be able to see which constraints are comparatively slow. And then it becomes a game of tweaking.

Upvotes: 2

Related Questions