This project has moved. For the latest updates, please go here.

Code Caching

Oct 28, 2016 at 2:20 PM
Hi,

Does ClearScript support code caching?

I am running v8 (using ClearScript and ReactJS.net) on asp.net and the first request takes about 10 second to run all the code and then subsequent requests takes about 200ms.

I profiled it and saw the v8 takes 90% of this 10 seconds, I suspect that if there is a way to expose v8 code caching I would able to build code cache on build time (using MSBuild step) and then later use the code cache.

Is this supported? and does it relates to: https://clearscript.codeplex.com/discussions/560532 ?

V8 Blog explains code caching: http://v8project.blogspot.co.il/2015/07/code-caching.html
Coordinator
Oct 31, 2016 at 11:40 AM
Hello yosy,

ClearScript 5.4.8 (the next point release) will support V8 code caching.

Thanks!
Coordinator
Nov 2, 2016 at 3:02 PM
Hi again,

ClearScript 5.4.8 is now available.

Good luck!
Nov 18, 2016 at 6:47 PM
Wow, that was fast!

Is there documentation available on how to use it?
Coordinator
Nov 18, 2016 at 8:46 PM
Hi yosy,

V8 caching support comes in the form of new overloads for the V8ScriptEngine.Compile and V8Runtime.Compile methods. For example, to compile a script and produce a code cache, you'd do something like this:
byte[] cacheBytes;
var script = engine.Compile(code, V8CacheKind.Code, out cacheBytes);
After that you could use the cache to accelerate recompilation:
bool cacheAccepted;
var script = engine.Compile(code, V8CacheKind.Code, cacheBytes, out cacheAccepted);
You can download an API reference here.

Good luck!
Feb 16 at 10:39 AM
How is this different from caching the compiled script, and wouldn't that be faster ?
Coordinator
Feb 16 at 11:46 AM
You can reuse cache data across V8 runtimes, or store it externally and reuse it across processes. Compiled scripts do not support these scenarios.