1. v8-compile-cache
Require hook for automatic V8 compile cache persistence
v8-compile-cache
Package: v8-compile-cache
Created by: zertosh
Last modified: Mon, 14 Aug 2023 21:38:46 GMT
Version: 2.4.0
License: MIT
Downloads: 56,363,197
Repository: https://github.com/zertosh/v8-compile-cache

Install

npm install v8-compile-cache
yarn add v8-compile-cache

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
  1. 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

  • FileSystemBlobStore and NativeCompileCache are based on Atom's implementation of their v8 compile cache:
    • https://github.com/atom/atom/blob/b0d7a8a/src/file-system-blob-store.js
    • https://github.com/atom/atom/blob/b0d7a8a/src/native-compile-cache.js
  • mkdirpSync is based on:
    • https://github.com/substack/node-mkdirp/blob/f2003bb/index.js#L55-L98

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin