[ 
https://issues.apache.org/jira/browse/SLING-913?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14060384#comment-14060384
 ] 

Carsten Ziegeler commented on SLING-913:
----------------------------------------

I think the patch in general is fine - I'm not sure about the new method, 
however if it's required (as you indicate), that's the only way to pass it from 
one part to the other.
While this definitely seems to improve things, I'm not 100% sure if the last 
modified approach is the best. We started with that within the jsp engine but 
found out later that this is actually a bottleneck as each and every script 
execution needs to check for the last modified which is a resource access 
(read). In addition this needed to be synchronized to avoid concurrent 
compilation. Under high load this slowed down things. Therefore we switched to 
event/observation based compilation. We might not need syncing in this case as 
compiling the same javascript script in parallel might not hurt that much 
though.
Therefore I guess we can start with this approach and see whether we run into 
trouble or not

> Add a cache for pre-compiled scripts
> ------------------------------------
>
>                 Key: SLING-913
>                 URL: https://issues.apache.org/jira/browse/SLING-913
>             Project: Sling
>          Issue Type: New Feature
>          Components: Scripting
>    Affects Versions: Scripting Core 2.0.2
>            Reporter: Felix Meschberger
>         Attachments: SLING-913.patch
>
>
> The Java Scripting API provides support for scripting langugages which may 
> precompile script source and reuse the precompiled scripts:
>   javax.script.Compilable: May be implemented by a ScriptEngine if 
> precompilation is
>           supported
>   javax.script.CompiledScript: Result of calling the Compilable.compile 
> method.
> The CompiledScript can be called to repeatedly execute the script without the 
> need for recompilation and thus for improved performance.
> The Sling Core Scripting support should make use of this functionality by 
> maintaining a cache compiled scripts with the following properties
>   * indexed by script path
>   * size limited (using LinkedHashMap overwriting the removeEldestEntry 
> method)
>   * entries are weak or soft references ot cache entries
> A cache entry consists of the following information:
>   * The CompiledScript instance
>   * The time of last compilation. this is compared to the last modification 
> time of the script to decide on whether to recompile
> We might probaly also try to add a reference to the script engine 
> implementation bundle to only use the cache entry if the bundle has not been 
> stopped since adding the cache entry
> Executing the script would then consist of the following steps:
>   1 Check the cache of precompiled scripts. if an entry exists and can be 
> used, use it
>   2. if the ScriptEngine is Compilable:
>       2a. Compile the script and add it to the cache and use it
>       2b. Otherwise have the script engine execute the script



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to