1
|
# v8-compile-cache
|
2
|
|
3
|
[](https://travis-ci.org/zertosh/v8-compile-cache)
|
4
|
|
5
|
`v8-compile-cache` attaches a `require` hook to use [V8's code cache](https://v8project.blogspot.com/2015/07/code-caching.html) to speed up instantiation time. The "code cache" is the work of parsing and compiling done by V8.
|
6
|
|
7
|
The ability to tap into V8 to produce/consume this cache was introduced in [Node v5.7.0](https://nodejs.org/en/blog/release/v5.7.0/).
|
8
|
|
9
|
## Usage
|
10
|
|
11
|
1. Add the dependency:
|
12
|
|
13
|
```sh
|
14
|
$ npm install --save v8-compile-cache
|
15
|
```
|
16
|
|
17
|
2. Then, in your entry module add:
|
18
|
|
19
|
```js
|
20
|
require('v8-compile-cache');
|
21
|
```
|
22
|
|
23
|
**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`.**
|
24
|
|
25
|
## Options
|
26
|
|
27
|
Set the environment variable `DISABLE_V8_COMPILE_CACHE=1` to disable the cache.
|
28
|
|
29
|
## Internals
|
30
|
|
31
|
The caches are stored in `$TMP/v8-compile-cache/V8_VERSION`, where there are `.BLOB` and `.MAP` files 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.
|
32
|
|
33
|
## Benchmarks
|
34
|
|
35
|
See https://github.com/zertosh/v8-compile-cache/tree/master/bench.
|
36
|
|
37
|
**Load Times:**
|
38
|
|
39
|
| Module | Without Cache | With Cache |
|
40
|
| ---------------- | -------------:| ----------:|
|
41
|
| `babel-core` | `218ms` | `185ms` |
|
42
|
| `yarn` | `153ms` | `113ms` |
|
43
|
| `yarn` (bundled) | `228ms` | `105ms` |
|
44
|
|
45
|
_^ Includes the overhead of loading the cache itself._
|
46
|
|
47
|
## Acknowledgements
|
48
|
|
49
|
* `FileSystemBlobStore` and `NativeCompileCache` are based on Atom's implementation of their v8 compile cache:
|
50
|
- https://github.com/atom/atom/blob/b0d7a8a/src/file-system-blob-store.js
|
51
|
- https://github.com/atom/atom/blob/b0d7a8a/src/native-compile-cache.js
|
52
|
* `mkdirpSync` is based on:
|
53
|
- https://github.com/substack/node-mkdirp/blob/f2003bb/index.js#L55-L98
|