-
-
Notifications
You must be signed in to change notification settings - Fork 428
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
[rules] Add support for pre-compilation of conditions and actions #4289
Conversation
@digitaldan FYI, while you are working on the great notification enhancements, I am not resting ;-) |
Awesome ! I actually saw #16970 first and asked a dumb question there, which could have been answered if i bothered reading that this was a dependency to it ;-) I'll take a look today ! |
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!
* | ||
* @return true if pre-compilation is supported, else false | ||
*/ | ||
default boolean supportsPreCompilation() { |
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.
Why do you need this method? Wouldn't it be sufficient to check if the script engine implements Compilable
?
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.
This would work as well, but then I would need to always initialize the script engine when the script action/condition is created, even if it does not implement Compilable. At the moment, the script engine is initialised on first use.
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.
Is that really an issue? If the engine implements Compilable
there is no extra-cost. If it doesn't it just shifts the time when the engine is created from first usage to startup (which probably also improves performance when the script is actually called).
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.
That's a good argument.
I thought there might be a reason it was implemented this way, but creating the engine at start up actually seems like a good idea. This also avoids that the memory usage seems to constantly grow over time.
I'll implement that.
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
…lation of scripts Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
…ctivating a rule Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
@J-N-K I implemented the requested changes. Otherwise the log will get spammed with:
It of course would be possible to add a check to the |
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
I went ahead and do now skip the compilation if no script engine is avalailable for the language. |
Thanks for merging! |
@jimtng FYI, not sure if JRuby Scripting need adjustments. |
@florian-h05 - I'm starting to see this in logs, is this expected?
I think it happens when loading DSL rules, I tried saving an empty rule:
|
No, this seems like a left-over from a previous version of this PR. |
See #4319. |
Fixes an issue, where an error that compilation failed for disabled rules. Reported on the community: https://community.openhab.org/t/oh-4-2-snapshot-disabled-rules-failed-to-compile-error-in-opehab-log/157402. Follow-up for #4289. Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Fixes openhab#17165. Caused by openhab/openhab-core#4289. Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Caused by openhab/openhab-core#4289. Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Caused by openhab/openhab-core#4289. Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
…UI scripts (#17171) * [jsscripting] Fix console logger name is missing for UI scripts * [jsscripting] Fix timer identifier "missing" for setTimeout/setInterval for UI scripts Fixes #17165. Caused by openhab/openhab-core#4289. Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
…UI scripts (openhab#17171) * [jsscripting] Fix console logger name is missing for UI scripts * [jsscripting] Fix timer identifier "missing" for setTimeout/setInterval for UI scripts Fixes openhab#17165. Caused by openhab/openhab-core#4289. 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/blockly-historic-state-average-ending-with-type-error/158191/11 |
…UI scripts (openhab#17171) * [jsscripting] Fix console logger name is missing for UI scripts * [jsscripting] Fix timer identifier "missing" for setTimeout/setInterval for UI scripts Fixes openhab#17165. Caused by openhab/openhab-core#4289. Signed-off-by: Florian Hotze <florianh_dev@icloud.com> Signed-off-by: Patrik Gfeller <patrik.gfeller@proton.me>
…UI scripts (openhab#17171) * [jsscripting] Fix console logger name is missing for UI scripts * [jsscripting] Fix timer identifier "missing" for setTimeout/setInterval for UI scripts Fixes openhab#17165. Caused by openhab/openhab-core#4289. Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
…UI scripts (openhab#17171) * [jsscripting] Fix console logger name is missing for UI scripts * [jsscripting] Fix timer identifier "missing" for setTimeout/setInterval for UI scripts Fixes openhab#17165. Caused by openhab/openhab-core#4289. Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
This PR adds the ability for the compilation of rule script conditions and script actions on openHAB start-up or rule creation.
This is achieved by:
ScriptEngine
on start-up or rule-creation and check if the ScriptEngine implementsCompilable
.Compilable.compile(script)
and store the returnedCompiledscript
on openHAB start-up or rule creation forScriptConditionHandler
andScriptActionHandler
.CompiledScript
instead of evaluating the script string if available.Script automation add-ons need to make sure that their
ScriptEngine
implements theCompilable
interface.The motivation behind this PR is to allow JS scripts (as for example created by Blockly) to be compiled before they are executed, so there is no delay for the first run, which is a huge UX improvement.
From a performance POV, the compilation on start-up behaves like all rules with pre-compilable script conditions/actions would have start level triggers and would run on start-up, but without actually executing the script.
JS Scripting implementation: openhab/openhab-addons#16970