New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V8 Compile Cache #51

Closed
rauchg opened this Issue Nov 25, 2018 · 2 comments

Comments

2 participants
@rauchg
Copy link
Contributor

rauchg commented Nov 25, 2018

The idea is that we can emit not just .js files, but also the v8 code cache blobs.
And unlike v8-compile-cache, we could benefit from making all bootups fast, including the first one. Also unlike it, we can use the new createCachedData APIs which have some benefits.

  • Make sure we disable the optimization gracefully when invoking in old Node versions
  • Make sure to add a flag to disable it (--no-v8-cache)

More:

@rauchg rauchg added the enhancement label Nov 25, 2018

@rauchg

This comment has been minimized.

Copy link
Contributor

rauchg commented Nov 25, 2018

It'd be neat to self-host this as well. Right now ncc takes 350ms~ to boot up, and the TypeScript compiler adds another 350ms~.

@rauchg rauchg referenced this issue Nov 26, 2018

Closed

Minification #62

@guybedford

This comment has been minimized.

Copy link
Collaborator

guybedford commented Dec 5, 2018

I just ran a simple test of the following code:

create-cache.js

const fs = require('fs');
const { Script } = require('vm');
const script = new Script(fs.readFileSync('./index.js').toString());
fs.writeFileSync('./index-cache', script.createCachedData());

index-cached.js

const fs = require('fs');
const source = fs.readFileSync('./index.js').toString();
const cachedData = fs.readFileSync('./index-cache');
const fs = require('fs');
const { Script } = require('vm');
const source = fs.readFileSync('./index.js').toString();
const cachedData = fs.readFileSync('./index-cache');
var s = new Script(source, { cachedData });
s.runInNewContext({
  module,
  exports,
  require,
  process,
  Buffer,
  console,
  global
});

where we then compare running time node index-cached.js and time node index.js.

Here are the results:

  • Analytics-node: 137ms uncached, 130ms cached
  • Twilio: 400ms uncached, 280ms cached
  • Canvas: 145ms uncached, 145ms cached

So it seems the benefit only really applies for very large builds... but it does seem like there is a benefit there in some cases, which may be enough to justify it as a custom flag.

I can basically replicate the above as a flag option... will do a PR now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment