Hi,

Bertrand Delacretaz schrieb:
> On Mon, Apr 6, 2009 at 11:00 AM, Felix Meschberger <[email protected]> wrote:
>> ...We should then probably also extend the Rhino script engine to cache
>> compiled ecma scripts and reuse them, similar to what the JSP script
>> engine does (no we probably don't need to write class files)....
> 
> This is something that we should do in any case, to improve ESP
> scripting performance.
> 
> Rhino does provide a compiler
> (https://developer.mozilla.org/en/Rhino_JavaScript_Compiler), haven't
> tested it yet.

This works, and I used it before ...

Rhino always runs scripts  in two phases: "compilation" and "execution".
The result of the first step is generally an instance of the Script
interface. This interface has a method to execute the script, which is
call by RHino in the second phase.

How about this approach, thus also leveraging the full scope of JSR 223
(Java Scripting): The Java Scripting API provides API to allow for
precompiled scripting languages. By leveraging this mechanism we can add
support for precompiled scripts and enhanced performance to all
scripting languages.

We maintain a script cache in the Scripting Core bundle. This cache has
the following attributes:

  * Indexed by script path name, entries are weak or soft references
    to JSR-223 CompiledScript instances (and some time stamp to help
    decide for recompilation)

  * When trying to run a script the following steps take place:

        - check for a cache entry
        - if existing and script source is not more recent
           than the cache entry, us it and we are done
        - if the cache entry is outdated, remove it and continue

        - check whether the ScriptEngine allows precompilation.
        - if yes: compile the script, enter it into the cache
            and run the CompiledScript
        - if no: just have the ScriptEngine read and run the
            script.

This can already be easily used for our own JSP Script Engine. It may
probably also be used for the Groovy ScriptEngine, since it supports
script precompilation. For our own Rhino ScriptEngine we would just add
support for this and be done.

WDYT ?

Regards
Felix

Reply via email to