Community
Participate
Working Groups
Calling the script engine for attribute calculations and conditions everytime might be performance-critical. Maybe it is possible to gain some speed by first checking in Java whether the attribute condition/value matches a parameter name or a constant. In these cases, the assignment/check can be done directly in Java without the need for calling the scriptengine. I can imagine that this saves some time.
The script engine is not called every time. The behavior for the different cases is at follows: 1) Attribute values without parameter like new Integer(5).toString() Those are passed to the script engine once for computation when the rule is used the first time. Afterwards the InterpreterEngine (at least the EmfEngine implementation) caches the result and will use it again for later rule applications. 2) Attribute value is parameter The parameter is set without the use of the script engine. If it is involved in attribute conditions see 3) 3) Attribute conditions Those are checked when all parameters for the condition are set. For example there are three variables x, y, z in three different nodes. An attribute condition with all three parameters will only be checked whenn all three nodes are matched. I don't see how this can be further improved, can you be more specific which case you have in mind?
(In reply to comment #1) > The script engine is not called every time. The behavior for the different > cases is at follows: > 1) Attribute values without parameter like new Integer(5).toString() > Those are passed to the script engine once for computation when the rule is > used the first time. Afterwards the InterpreterEngine (at least the EmfEngine > implementation) caches the result and will use it again for later rule > applications. So this holds for constants, right? Another question: your example looks like Java. The default is JavaScript though, right? > > 2) Attribute value is parameter > The parameter is set without the use of the script engine. If it is involved in > attribute conditions see 3) That is the case I meant. So the engine is not used here. Good. > > 3) Attribute conditions > Those are checked when all parameters for the condition are set. For example > there are three variables x, y, z in three different nodes. An attribute > condition with all three parameters will only be checked whenn all three nodes > are matched. > > I don't see how this can be further improved, can you be more specific which > case you have in mind? Yes, that looks good. Thanks for the clarifications.
Yes, any expression that can be evaluated (those without parameters) will be evaluated once. This is especially true for primitive constants like "Hello" or 5. The expressions are JavaScript and are evaluated by the RhinoScriptEngine.