You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Marius Andrei Danila <md...@adobe.com> on 2014/04/08 10:18:25 UTC

[JavaScript] Caching javascript compilation objects

Hello everyone,

I’m encountering some performance problems when running JS scripts in Sling and after looking at the Rhino script engine it seems that the engine does not cache the compiled version of the script being run. This means that for each JS source, the Rhino engine will compile the content into byte code, then execute it. Running does not usually incur much overhead for relatively small scripts - but compilation is a very expensive process.

Is there any way to avoid recompilation at each run, or is there something wrong with the scenario I’ve described above?

I know Rhino provides two solutions to this:

1. Create an in-memory representation of the compiled script [0]
2. Use the dedicated compiler to generate a .class file [1]

Can we leverage this to implement caching of JS scripts in Sling?

All the best,
Marius

[0] http://www-archive.mozilla.org/rhino/apidocs/org/mozilla/javascript/Context.html#compileReader(java.io.Reader, java.lang.String, int, java.lang.Object)<http://www-archive.mozilla.org/rhino/apidocs/org/mozilla/javascript/Context.html#compileReader(java.io.Reader,%20java.lang.String,%20int,%20java.lang.Object)>
[1] https://developer.mozilla.org/en/docs/Rhino/JavaScript_Compiler

Re: [JavaScript] Caching javascript compilation objects

Posted by Carsten Ziegeler <cz...@apache.org>.
Hi,

yes I think this should be possible. In addition, the cache needs to be
invalidated when a script changes, but we have resource events for this.

Regards
Carsten


2014-04-08 10:18 GMT+02:00 Marius Andrei Danila <md...@adobe.com>:

> Hello everyone,
>
> I’m encountering some performance problems when running JS scripts in
> Sling and after looking at the Rhino script engine it seems that the engine
> does not cache the compiled version of the script being run. This means
> that for each JS source, the Rhino engine will compile the content into
> byte code, then execute it. Running does not usually incur much overhead
> for relatively small scripts - but compilation is a very expensive process.
>
> Is there any way to avoid recompilation at each run, or is there something
> wrong with the scenario I’ve described above?
>
> I know Rhino provides two solutions to this:
>
> 1. Create an in-memory representation of the compiled script [0]
> 2. Use the dedicated compiler to generate a .class file [1]
>
> Can we leverage this to implement caching of JS scripts in Sling?
>
> All the best,
> Marius
>
> [0]
> http://www-archive.mozilla.org/rhino/apidocs/org/mozilla/javascript/Context.html#compileReader(java.io.Reader,
> java.lang.String, int, java.lang.Object)<
> http://www-archive.mozilla.org/rhino/apidocs/org/mozilla/javascript/Context.html#compileReader(java.io.Reader,%20java.lang.String,%20int,%20java.lang.Object)
> >
> [1] https://developer.mozilla.org/en/docs/Rhino/JavaScript_Compiler
>



-- 
Carsten Ziegeler
cziegeler@apache.org