avajs/ava

Investigate using Node 5.7.0's cachedData support

novemberborn opened this issue · 1 comments

Node 5.7.0 adds produceCachedData and cachedData options to new vm.Script(). We might be able to produce cached data for the child process bootstrap code (including custom require hooks) and use that to improve startup time for each fork.

See API docs. Background in nodejs/node#4777.

http://v8project.blogspot.co.uk/2015/07/code-caching.html provides a explanation of this feature:

V8 uses just-in-time compilation (JIT) to execute Javascript code. This means that immediately prior to running a script, it has to be parsed and compiled - which can cause considerable overhead. (…) code caching is a technique that lessens this overhead. (…)

When a script is compiled by V8, cache data can be produced to speed up later compilations (…) During later compilations, the previously produced cache data can be attached to the source object (…). This time, code will be produced much faster, as V8 bypasses compiling the code and deserializes it from the provided cache data.

However only the source passed to vm.Script() can be cached. To make most use of this feature I think we'd have to combine test-worker.js and it's dependencies into a single source string. We'd have to properly instantiate modules and populate the require cache when the combined source is evaluated.

If we ever get to that point we'll already have a fair amount of performance gain anyway just because there'll less disk access, though it'll be interesting to see to what extend caching the compilation data can help.