You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Felix Meschberger <fm...@gmail.com> on 2009/04/06 11:55:03 UTC
Re: Support for Java Scripting Script Precompilation
Hi,
Bertrand Delacretaz schrieb:
> On Mon, Apr 6, 2009 at 11:32 AM, Felix Meschberger <fm...@gmail.com> wrote:
>> Hi,
>>
>> Bertrand Delacretaz schrieb:
>>> On Mon, Apr 6, 2009 at 11:00 AM, Felix Meschberger <fm...@gmail.com> 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)....
>>> ...Rhino does provide a compiler
>>> (https://developer.mozilla.org/en/Rhino_JavaScript_Compiler)...
>
>> ...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)
>
> Ok. I think this cache should also have some form of size limitation -
> maybe simply limit the total number of CompiledScript instances in the
> cache, and purge least recently used entries when that limit is
> reached?
Sure. And of course the limit would be configurable ;-)
I just failed to add this other restriction
Regards
Felix
>
>> ... * 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
>
> ok
>
>> - 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.
>
> ok
>
>> 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.
>
> Sound great!
> -Bertrand
>