-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[jsscripting] Cache openhab-js injection to improve performance #14135
Conversation
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
On my dev system (which I guess is much more powerful than most openHAB servers), cached openhab-js injection takes 100-200 ms. openhab-js injection from file system takes about 1000 ms. This depends on changes to the openhab-js library that have not been released yet. Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! I have a few comments regarding configuration language as you requested, nothing major. Changes in code looks good to me, was planning on getting my 4.0 environment up today and see if i can test this.
bundles/org.openhab.automation.jsscripting/src/main/resources/OH-INF/config/config.xml
Outdated
Show resolved
Hide resolved
bundles/org.openhab.automation.jsscripting/src/main/resources/OH-INF/config/config.xml
Outdated
Show resolved
Hide resolved
bundles/org.openhab.automation.jsscripting/src/main/resources/OH-INF/config/config.xml
Outdated
Show resolved
Hide resolved
Also-by: Dan Cunningham >dan@digitaldan.com> Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Thanks :-)
This PR depends on openhab/openhab-js#218. |
@florian-h05 - great work again. I'm wondering if it would be possible to also cache the library from |
Thanks :-)
I was trying this, but unfortunantely code caching for loaded code (via
This is mainly thought for openhab-js updates in case you need a yet not addon included fix or enhancement. I have the feeling that openhab-js is now in a well-tested and stable state and I hope that in the future there are not as many changes as in the past, so I hope when 4.0 is released in summer, you can live with the included version and won't miss something from the latest openhab-js. |
…k changes Documentation updates will follow in another PR to keep this one clean. Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Only a minor comment about consistent naming.
bundles/org.openhab.automation.jsscripting/src/main/resources/OH-INF/config/config.xml
Outdated
Show resolved
Hide resolved
...ng/src/main/java/org/openhab/automation/jsscripting/internal/OpenhabGraalJSScriptEngine.java
Outdated
Show resolved
Hide resolved
...ng/src/main/java/org/openhab/automation/jsscripting/internal/OpenhabGraalJSScriptEngine.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
...les/org.openhab.automation.jsscripting/src/main/resources/OH-INF/i18n/jsscripting.properties
Outdated
Show resolved
Hide resolved
Signed-off-by: Florian Hotze <florianh_dev@icloud.com> Co-authored-by: Jacob Laursen <jacob-github@vindvejr.dk>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
@florian-h05 does const ns = {};
// assign everything in @oh, so items, actions, triggers, etc....
Object.assign(ns, require("openhab"));
.....
module.exports = ns; i then add some proxy magic for my own helper functions and export the whole thing. This is throwing errors that it can't find |
Oh yes, I see the problem. |
…#14135 Fixes the regression from openhab#14135 (comment), I noticed that the cached openhab-js injection does not work. While working on this, I also noticed that the cache openhab-js does not work because of wrong webpack commandline args in the pom (wrong entrypoint). Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
…#14135 Fixes the regression from openhab#14135 (comment). While working on this, I also noticed that the cache openhab-js does not work because of wrong webpack commandline args in the pom (wrong entrypoint). Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
…mentException` (#14142) * [jsscripting] Fix bundling of global script & regression from #14135 Fixes the regression from #14135 (comment). While working on this, I also noticed that the cache openhab-js does not work because of wrong webpack commandline args in the pom (wrong entrypoint). * [jsscripting] Enable stack logging for IllegalArgumentExceptions * [jsscripting] Upgrade openhab-js to 3.2.4 * [jsscripting] Update README for recent PR Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/oh3-to-use-or-not-to-use-js-ecmascript-2021/141911/11 |
…hab#14135) * [jsscripting] Extend comments for wraprequire * [jsscripting] Enable openhab-js caching to improve performance On my dev system (which I guess is much more powerful than most openHAB servers), cached openhab-js injection takes 100-200 ms. openhab-js injection from file system takes about 1000 ms. * [jsscripting] Update configuration language * [jsscripting] Upgrade openhab-js version to 3.2.1 for required webpack changes Documentation updates will follow in another PR to keep this one clean. Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
…galArgumentException` (openhab#14142) * [jsscripting] Fix bundling of global script & regression from openhab#14135 Fixes the regression from openhab#14135 (comment). While working on this, I also noticed that the cache openhab-js does not work because of wrong webpack commandline args in the pom (wrong entrypoint). * [jsscripting] Enable stack logging for IllegalArgumentExceptions * [jsscripting] Upgrade openhab-js to 3.2.4 * [jsscripting] Update README for recent PR Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
…hab#14135) * [jsscripting] Extend comments for wraprequire * [jsscripting] Enable openhab-js caching to improve performance On my dev system (which I guess is much more powerful than most openHAB servers), cached openhab-js injection takes 100-200 ms. openhab-js injection from file system takes about 1000 ms. * [jsscripting] Update configuration language * [jsscripting] Upgrade openhab-js version to 3.2.1 for required webpack changes Documentation updates will follow in another PR to keep this one clean. Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
…galArgumentException` (openhab#14142) * [jsscripting] Fix bundling of global script & regression from openhab#14135 Fixes the regression from openhab#14135 (comment). While working on this, I also noticed that the cache openhab-js does not work because of wrong webpack commandline args in the pom (wrong entrypoint). * [jsscripting] Enable stack logging for IllegalArgumentExceptions * [jsscripting] Upgrade openhab-js to 3.2.4 * [jsscripting] Update README for recent PR Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
…hab#14135) * [jsscripting] Extend comments for wraprequire * [jsscripting] Enable openhab-js caching to improve performance On my dev system (which I guess is much more powerful than most openHAB servers), cached openhab-js injection takes 100-200 ms. openhab-js injection from file system takes about 1000 ms. * [jsscripting] Update configuration language * [jsscripting] Upgrade openhab-js version to 3.2.1 for required webpack changes Documentation updates will follow in another PR to keep this one clean. Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
…galArgumentException` (openhab#14142) * [jsscripting] Fix bundling of global script & regression from openhab#14135 Fixes the regression from openhab#14135 (comment). While working on this, I also noticed that the cache openhab-js does not work because of wrong webpack commandline args in the pom (wrong entrypoint). * [jsscripting] Enable stack logging for IllegalArgumentExceptions * [jsscripting] Upgrade openhab-js to 3.2.4 * [jsscripting] Update README for recent PR Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/oh3-to-use-or-not-to-use-js-ecmascript-2021/141911/24 |
For previous discussion see #14113.
Description
This PR extends the code caching to the version of the openHAB JavaScript library (openhab-js) that is included in the JS Scripting addon.
A new configuration option is introduced to allow the user to disable usage of the internal openhab-js library and instead load it from the file system.
Note: I am currently not super happy with the description and the label of that new configuration option, I would like to get some feedback on them.Code caching of the openhab-js injection brings great performance improvements as the evaluation of the pretty large openhab-js codebase takes some time.
Note: it is not possible to cache the
Object.assign(this, require("openhab");
therefore I had to take the way of creating an injection script at openhab-js.I've performed a few test runs on my dev system (that is quite powerful, AMD Ryzen 7) and here are the results:
On my Raspberry Pi 3 (Debian 10 Buster), caching makes a even larger difference:
Note that evaluation of the cached version takes a bit longer than usual after the first start of the addon -- the code needs to be evaluated once before it is cached.
To Do
Ping @digitaldan @jlaur