Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 333233 - [Interpreter] Performance gain in attribute calculations?
Summary: [Interpreter] Performance gain in attribute calculations?
Status: RESOLVED WORKSFORME
Alias: None
Product: EMFT.Henshin
Classification: Modeling
Component: Interpreter (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-27 05:29 EST by Christian Krause CLA
Modified: 2011-01-05 06:38 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christian Krause CLA 2010-12-27 05:29:46 EST
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.
Comment 1 Enrico Biermann CLA 2011-01-04 10:46:25 EST
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?
Comment 2 Christian Krause CLA 2011-01-04 12:27:13 EST
(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.
Comment 3 Enrico Biermann CLA 2011-01-05 06:38:42 EST
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.