v8-compile-cache icon indicating copy to clipboard operation
v8-compile-cache copied to clipboard

Newer V8 code caching features

Open hashseed opened this issue 7 years ago • 6 comments

Very interesting project. I think you can benefit from some of the newer features we added to code caching in V8.

The current API compiles the top-level code and immediately puts that compilation result into the code cache. Inner functions are compiled lazily and not included in the cache. We recently introduced a new compile option that forces V8 to compile every function in the source so that we end up with more data in the code cache.

We also introduced a new API to produce the code cache not immediately after compilation, but at a later point when some execution might already have happened, at which point we may have compiled more functions.

I know none of this are yet available in Node.js since the newest V8 has not rolled into Node.js yet, and even then you have to expose these new API in a suitable way.

But I thought this might interest you in the long run.

hashseed avatar Dec 06 '17 19:12 hashseed

@hashseed Any updates on if or when these things might make it into Node?

jdalton avatar Feb 10 '18 08:02 jdalton

This new API I mentioned here should be in Node.js once it upgrades to V8 6.5. It might need to be exposed via vm module to become easily accessible though.

hashseed avatar Feb 10 '18 09:02 hashseed

Is it available now we have Node 10?

robpalme avatar Apr 26 '18 13:04 robpalme

It's getting there, but not quite in Node 10 yet. Maybe we'll still get it before the Node 10 LTS ship sails :)

https://github.com/nodejs/node/issues/20052

hashseed avatar Apr 26 '18 13:04 hashseed

We recently introduced a new compile option that forces V8 to compile every function in the source so that we end up with more data in the code cache.

@hashseed I think this isn't in Node yet, do you happen to know if there are plans to expose it? I've looked at createCachedData but sadly it doesn't seem to include the option to force compilation, unless I'm missing something?

jscheid avatar Oct 15 '18 21:10 jscheid

This is already in Node 10.6.0 and above. We should attempt to fix this. https://nodejs.org/api/vm.html#vm_script_createcacheddata

Here is an example: https://github.com/vercel/ncc/pull/112 by @guybedford

aminya avatar Sep 29 '20 17:09 aminya