包详细信息

v8-compile-cache

zertosh48.6mMIT2.4.0

Require hook for automatic V8 compile cache persistence

自述文件

v8-compile-cache

Build Status

v8-compile-cache attaches a require hook to use V8's code cache to speed up instantiation time. The "code cache" is the work of parsing and compiling done by V8.

The ability to tap into V8 to produce/consume this cache was introduced in Node v5.7.0.

Usage

  1. Add the dependency:

    $ npm install --save v8-compile-cache
    
  2. Then, in your entry module add:

    require('v8-compile-cache');
    

Requiring v8-compile-cache in Node <5.7.0 is a noop – but you need at least Node 4.0.0 to support the ES2015 syntax used by v8-compile-cache.

Options

Set the environment variable DISABLE_V8_COMPILE_CACHE=1 to disable the cache.

Cache directory is defined by environment variable V8_COMPILE_CACHE_CACHE_DIR or defaults to <os.tmpdir()>/v8-compile-cache-<V8_VERSION>.

Internals

Cache files are suffixed .BLOB and .MAP corresponding to the entry module that required v8-compile-cache. The cache is entry module specific because it is faster to load the entire code cache into memory at once, than it is to read it from disk on a file-by-file basis.

Benchmarks

See https://github.com/zertosh/v8-compile-cache/tree/master/bench.

Load Times:

Module Without Cache With Cache
babel-core 218ms 185ms
yarn 153ms 113ms
yarn (bundled) 228ms 105ms

^ Includes the overhead of loading the cache itself.

Acknowledgements

更新日志

v8-module-cache Changelog

Next

2023-08-14, Version 2.4.0

  • Fix segmentation fault with Rosetta on Apple Silicon #45.

2021-03-05, Version 2.3.0

  • Fix use require.main instead of module.parent #34.

2020-10-28, Version 2.2.0

  • Added V8_COMPILE_CACHE_CACHE_DIR option #23.

2020-05-30, Version 2.1.1

  • Stop using process.umask() #28.

2019-08-04, Version 2.1.0

  • Fix Electron by calling the module wrapper with Buffer #10.

2019-05-10, Version 2.0.3

  • Add LICENSE file #19.
  • Add "repository" to package.json (see eea336e).
  • Support require.resolve.paths (added in Node v8.9.0) #20/#22.

2018-08-06, Version 2.0.2

  • Re-publish.

2018-08-06, Version 2.0.1

  • Support require.resolve options (added in Node v8.9.0).

2018-04-30, Version 2.0.0

  • Use Buffer.alloc instead of new Buffer().
  • Drop support for Node 5.x.

2018-01-23, Version 1.1.2

  • Instead of checking for process.versions.v8, check that script.cachedDataProduced is true (rather than null/undefined) for support to be considered existent.

2018-01-23, Version 1.1.1

  • Check for the existence of process.versions.v8 before attaching hook (see f8b0388).

2017-03-27, Version 1.1.0

  • Safer cache directory creation (see bcb3b12).
    • The cache is now suffixed with the user's uid on POSIX systems (i.e. /path/to/tmp/v8-compile-cache-1234).

2017-02-21, Version 1.0.0

  • Initial release.