Socket
Socket
Sign inDemoInstall

v8-compile-cache

Package Overview
Dependencies
0
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    v8-compile-cache

Require hook for automatic V8 compile cache persistence


Version published
Weekly downloads
13M
increased by1.48%
Maintainers
2
Install size
14.6 kB
Created
Weekly downloads
 

Package description

What is v8-compile-cache?

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.

What are v8-compile-cache's main functionalities?

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');

Other packages similar to v8-compile-cache

Readme

Source

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:

ModuleWithout CacheWith Cache
babel-core218ms185ms
yarn153ms113ms
yarn (bundled)228ms105ms

^ Includes the overhead of loading the cache itself.

Acknowledgements

FAQs

Last updated on 14 Aug 2023

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc