Code Caching

Oct 28, 2016 at 3:20 PM

Does ClearScript support code caching?

I am running v8 (using ClearScript and on 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: ?

V8 Blog explains code caching:
Oct 31, 2016 at 12:40 PM
Hello yosy,

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

Nov 2, 2016 at 4:02 PM
Hi again,

ClearScript 5.4.8 is now available.

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

Is there documentation available on how to use it?
Nov 18, 2016 at 9: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 11:39 AM
How is this different from caching the compiled script, and wouldn't that be faster ?
Feb 16 at 12:46 PM
You can reuse cache data across V8 runtimes, or store it externally and reuse it across processes. Compiled scripts do not support these scenarios.