Security News
The Dark Side of Open Source
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
v8-compile-cache
Advanced tools
Package description
The v8-compile-cache package leverages V8's code caching capabilities to significantly speed up loading time of JavaScript modules in Node.js. By caching the compiled code of modules, it reduces the overhead of parsing and compiling scripts on every execution, leading to faster startup times for applications.
Enabling V8 Compile Cache
This is the basic usage to enable V8 compile cache in a Node.js application. By simply requiring the package at the beginning of your main script, it automatically hooks into the require system to cache compiled modules.
require('v8-compile-cache');
Similar to v8-compile-cache, @babel/register compiles your files on the fly. However, it focuses on transforming ES6+ code into backward-compatible JavaScript, rather than caching compiled code for performance.
Pirates provides a simple API to add custom require hooks, which can be used for transpiling code on the fly, similar to what v8-compile-cache does. However, it doesn't cache the compiled output by default, focusing instead on the transformation aspect.
Readme
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.
$ npm install --save v8-compile-cache
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
.
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>
.
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.
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.
FileSystemBlobStore
and NativeCompileCache
are based on Atom's implementation of their v8 compile cache:
mkdirpSync
is based on:
FAQs
Require hook for automatic V8 compile cache persistence
The npm package v8-compile-cache receives a total of 12,428,684 weekly downloads. As such, v8-compile-cache popularity was classified as popular.
We found that v8-compile-cache demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
Research
Security News
The Socket Research team found this npm package includes code for collecting sensitive developer information, including your operating system username, Git username, and Git email.
Security News
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.