GraalVM itself is a fully compatible replacement for OpenJDK/OracleJDK. So there should not be a compatibility problem IF there is a version available. But I guess GraalVM is not available on every platform you mention.
The JS Scripting add-on provides GraalVM JS.
That is not a supported (expected) way of executing Graal.js. It is possible, but without GraalVM as the underlying optimizing compiler, you lose performance (exactly what you experience). There might be ways around that limitation, see Run GraalVM JavaScript on a Stock JDK - but again, that support might change over time.
unless GraalVM can support Jav 17
We are on latest Java version(s) available. Published is Java 20, our main line (to be published soonish) is Java 21 and we are working on 22 already. LTS branches offer support for Java 17. See www.graalvm.org/downloads
we also need to be careful about licensing.
Agreed, but I donāt think there is a difference between using Graal.js or the whole GraalVM.
Given the way OH is built and the fact that GraalVM JS is an option, not a requirement (though as an option it needs to run everywhere we want OH to run and RPis are our biggest install base), based on what I can tell so far, it would require quite some compromises to OH overall. It seems like we would need to throw out all the other rules languages we currently support or live with the performance. And itās not clear to me that runtime development of rules would be possible. All the descriptions talk about compiling the app into a binary which seems to preclude that as an option.
It would be interesting to see what we can do to make it better. Iām not sure whether/how those command line arguments passed to the JRE are handled in an OSGi context. Clearly something is done to enable the JIT when the add-on is installed since it works. The module-path and upgrade-module-path have to be there somehow. But I donāt know if those other arguments are handled (-XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler). Maybe those are required too in order to work at all in which case they have to be there too.
I might experiment a bit but over all Iām quickly approaching the limits of my knowledge.
It seems like we would need to throw out all the other rules languages
I donāt see why this would be necessary. You are using OpenJDK (?) now. You use GraalVM in the future. Everything else stays the same. All other (Java-based) tools work just as before.
All the descriptions talk about compiling the app into a binary
You are referring to GraalVM Native Image, which is a component of GraalVM, but not one you would be using. Youād be using the ānormalā Java JIT compiler (ājava.exeā).
what we can do to make it better
Without GraalVM: very little. Whatever you do wonāt fix the root problem that the JavaScript code is not compiled. Nashorn does that by generating Bytecode; GraalVM has itās own trick of doing that (called partial evaluation). The other options (as listed in the article I linked in my previous post) will work on any 11+ Java VM and are required to enable GraalVM as (one of the) optimizing compiler(s). Will still require to download and provide GraalVMās optimizing compiler, which might not be available on every platform (or not be suitable, due to size limitations, etc.).
Nice to see, that the discussion about this topic has started and experts are involved.
I personal, as several times told now, have no problem if my notifications rules run 1 sec (on 3.4.4)
on now 30 sec on 4.0.2 to inform me, that outside rain has started, or bike charging has finished.
Real total not interesting for me. But I assume other users have the need here that rules run fast.
The funny thing is, that with the flag, (āDo Not Use Globalsā), the dsl and javascript rule run fast,
but the Blockly will not more run. For my personal ~50% of my rules from total ~70 rules which way I go whith the flag or not, are impacted.
Thanks to all the contributors to find a suitable solution for an upcomming OH release to combine the run of blockly rules, and fast DSL and Java scriptsā¦
The āDo Not Use Globalsā flag is for and only used by JS Scripting. So itās only going to impact the JS Scripting add-on and stuff that uses JS Scripting. As mentioned above, Blockly uses JS Scripting.
Rules DSL is not impacted at all, nor are any of the other rules languages.
In past under OH 3.4.4. with Java11 nothing has to set.
DSL, JavaScripts and Blockly were running fast without any user attentionā¦
Now under 4.x?
Java Scripting needs to be installed as add on.
DSL Rules runs normal
and you can select, a flag for JavaScripting to run fast but then Blockly run not more.
This is getting inappropriate.
You should be glad that after removal of Nashorn from Java we still can offer both solutions. And for giving you the choice, you need to install the appropriate addon.
I didnāt actually realize there was a performance difference by including GraalVM as a dependency, so that is something new to think about. @florian-h05 might find this fact interesting as well. Thanks @wirthi for letting us know ! I want to give this some more thought, and run a few tests on my home system, and maybe on a resource constrained one like on a Raspberry Pi 3 which i have a few running around the house. I think running GraalVM as an alternative JVM is very much an option, after all i think flexibility and choice and how people can run openHAB is a strength of ours. Iām out of town for a few days, so this may have to wait for next week. Iām also interested in this as i am still pursuing running matter.js in GraalVM as a possible Matter implementation, and optimized performance might be desirable.
This is totally misrepresenting the situation. You make it sound like the helper library is only there to slow everything down.
Iāve already outlined out how this works. Iāll just post an example of what the difference is between not using the helper library (which is the only way to ārun fastā) and not using the helper library.
Here is a simple rule I run at sundown to reset a flag in the Item metadata that gets set when someone manually changes a light during the day.
With the helper library:
console.debug('Looping through the lights');
items.TOD_Lights_ON_WEATHER.members.forEach( light => {
console.debug('Current override for ' + light.name + ' is ' + light.getMetadata('LightsOverride').value);
light.replaceMetadata('LightsOverride', 'false');
})
Notice half the rule is just logging. Without the logging itās a one liner
Our GraalJS-based JavaScript Scripting add-on is working the way you think - we just include the required Maven artifacts.
I have actually already tried out GraalVM on both my dev and prod systems, and it is running fine on my production system (Debian x86_64). However I havenāt thought that it makes such a large performance difference ā¦
Unfortunately GraalVM as a JDK has no support for 32-bit ARM, which I guess is one of the main architechtures openHAB is running on. At least older openHABian installations are only 32-bit, and I guess most people install 32-Bit only because on the release page, where you download openHABian there is a warning for 64-Bit and increased memory usage.
So the best option would be to enable GraalVM as optimizing compiler.
I will see if I can do a few performance tests.
@digitaldan Thanks for pinging me, otherwise I would have missed that very interesting conversation here.
Would it feasible/reasonable to offer GraalVM where itās supported and on 32-bit ARM only offer OpenJDK?
This is more of a distribution/openHABian/documentation question than a technical question I think. I suppose it depends on the extent of the performance improvement from running on GraalVM.
Rich, only to show you one example. So real no rocket tech behind.
Iām runnig a rule when my networkcam is not more reachable with a ping command.
Then I get a mail and a Whatsapp.
From thoose rules an other Iām have arround 70.
In 3.4.4 Iām getting the WA in 1 sec, under 4.0.2 or 4.03 it takes 30 sec.
Also a lot from my rules have combination from JS Scripting, Blockly and DSL in one ruleā¦
DSL Part
val mailActions = getActions("mail","mail:smtp:123456")
mailActions.sendMail("max.mustermann@web.de", "### ALARM ### ALARM ###", "Die Netzwerkkamera auĆen ist offline gegangen.")
JS Scripting Part
var HttpUtil = Java.type("org.openhab.core.io.net.http.HttpUtil")
var urlmessage = encodeURI("Die Kamera im AuĆenbereich ist OFFLINE gegangen.")
HttpUtil.executeUrl("GET", "https://api.callmebot.com/whatsapp.php?source=openHAB&phone=+123456789&apikey=12345678text=" + urlmessage , 2000)
But the experts are now here and talk positive about an upcomming solution.
Iām not 100% sure what you are seeing is related.
Everything the experts are talking about here has to do only with the first run of the rule. Once it runs that first time it should run fast from that point onward. The part that is slow is loading the helper library and that only happens on that first run.
Note, every time you open and save the rule, you are forcing that first run again so by doing that your are making the problem worse.
If it slow all the time, what ever is being discussed here isnāt going to fix it. As discussed in this an other threads, those reported cases of this behavior have been caused by overloaded machines.
BUT the fact, that it runs after the 2nd. time faster only works, when the rule was not disabeld between the 1.st run and the 2.nd run.
If the rule e.g.normal is enablend during daytime and disabled during night, and will be enabled at the next morning it has exactly this effect, that it is slow again.
This was not the case in 3.4.4ā¦
BTW: In my case the rules are not open, closed and saved. I only press the āplay buttonā to run it for testing.
Note, every time you open and save the rule, you are forcing that first run again so by doing that your are making the problem worse.
I admit I didnāt expressly say enable/disable but itās the same thing.
You keep saying that. We know! And itās irrelevant. You are not using 3.4.4. You are not using the same language as 3.4.4 any more. Itās a wholly new underlying language and technology. Why? Because the old 3.4.4 implementation was awkward to use based on a ten year old version of JS which is not actively supported by anyone any more.
And weāve already identified why and have people looking into that.
Iāll state the problem again, with more details.
The first time a rule is run after it is created, modified, enabled, or loaded (on system restart) it takes extra time for the helper library to be injected into the rule.
If your rules are slow and do not fit that description, open a new thread because nothing in this thread is going to be relevant.
If that does describe your rules, some work is being done to look into whether we can make this better for some users in some cases (if you are on a 32-bit Raspberry Pi OS you might be out of luck.
I also agree with @hmerk, that feels like an anti-pattern though more details are necessary. Usually the conditions are used for something like this.