java-Process spikes to over 100% on Rule-Save

Hi,
have a strange behavior in OH3 SnapShot-Build (don’t know if it happens in stable…)
After modifying a Rules-File and saving it, the openhab-java-process spikes up and over 100% for at least 30 Seconds or even longer and during that time openhab is nearly doing nothing else rules-wise.

I could break it down to one line of my code (had a couple of those, resulting in the long long “pause”):

logInfo(“Test”,"Result is: " + (5 + (2 * nCount)))

As soon as I comment out this line, saving is instantly done and the rule-file is loaded and everyting is ready.

Of course, I could pre-calculate the “Result”, but I can’t imagine that this is such a no-go for the rule-proccesing-engine.

Actualy, I made the effort and precalculated the Result. the CPU spikes still for a few Seconds to over 100%.

nCount = 3
nResult = 5 + (2 * nCount)
logInfo(“Test”,"Result is: " + nResult)

If I change the order for nResult like

nResult = (2 * nCount) + 5

there is no spike noticeable at all… O_O

But Math-Wise, there is no difference, or is there?

That’s normal behavior for any rule. When you save a change, it recompiles the rules and then a 2nd time when the rule is used for the first time.
Don’t edit live rules files but offline copies then copy those over when done.

The “old” OH2 DSL rule engine always had an odd quirk, and performed badly when pre-compiling maths expressions involving integers.

There’s no reason to suppose the new engine replicates this quirk … nor any reason to think it does not, either.

The circumvention was to deal with Number type variables instead. If you needed true integer result, take that at point of use not calculation e.g. xxx.intValue

Yes there is because that wasn’t the rules engine in OH2 to be lame on that but the “compiler”.
Which is unchanged in OH3 so still applies in principle. Sure other stuff like java version improved so it’s no longer as bad, but in principle it still takes long to compile DSL rules, it isn’t instanteanous at all.

Hmm, haven‘t done „offline-editing rules-files“ ever… it’s way faster for me to develop and debug if necessary this way. Hadn’t ever such issues.
And the recompile is running smoothly for any other rules-file. Also as mentioned, if I comment out those lines, the recompile of the rules-file in question is blazing fast.
Was just wondering with this kind of behavior.

Wasn’t aware of that. Thanks for the hint!

It feels at least instantaneous in my case when editing and saving the dsl-rules-files :slight_smile:

But as soon as I have a bit time on hand, I will have a look at the new engine and probably transfer my rules :slight_smile:

Thanks so far!