Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove v8-compile-cache #6904

Closed
ybiquitous opened this issue Jun 5, 2023 · 4 comments · Fixed by #6907
Closed

Remove v8-compile-cache #6904

ybiquitous opened this issue Jun 5, 2023 · 4 comments · Fixed by #6907
Labels
status: wip is being worked on by someone type: refactor an improvement to the code structure

Comments

@ybiquitous
Copy link
Member

Split from #6898
See also zertosh/v8-compile-cache#30

We've used v8-compile-cache for startup performance:

// to use V8's code cache to speed up instantiation time
require('v8-compile-cache');

But #6898 exposed a problem with ESM and dynamic imports.

If there are no big performance penalties or concerns, we'd like to remove v8-compile-cache to prevent future issues.

@ybiquitous ybiquitous added the status: needs discussion triage needs further discussion label Jun 5, 2023
@ybiquitous
Copy link
Member Author

Ref: #6901

@ybiquitous
Copy link
Member Author

I'm looking into this. v8-comple-cache was added by:

This was inspired by ESLint:

However, ESLint removed v8-comple-cache by:

@ybiquitous
Copy link
Member Author

v8-compile-cache is a blocker towards the migration to ESM:

@ybiquitous
Copy link
Member Author

ybiquitous commented Jun 6, 2023

I tried a benchmark with the following script (saving scripts/benchmark-v8-compile-cache.js):

'use strict';

/* eslint-disable no-console */

const cp = require('child_process');
const Benchmark = require('benchmark');

const cmdArgs = ['../bin/stylelint.js', 'visual.css', '-c', 'visual-config.json'];
const cwd = __dirname;

const suite = new Benchmark.Suite('test v8-compile-cache', {
	onStart() {
		try {
			cp.execFileSync('node', cmdArgs, { cwd });
		} catch (e) {
			if (e.status === 2) {
				// ignore
			} else {
				throw e;
			}
		}
	},
	onComplete(event) {
		const s = event.currentTarget;
		const fastest = s.filter('fastest').map('name');

		console.log(`Fastest is "${fastest}"`);
	},
});

suite.add('enable cache', {
	defer: true,
	fn(deferred) {
		const env = { ...process.env };

		cp.execFile('node', cmdArgs, { cwd, env }, () => deferred.resolve());
	},
	onComplete(event) {
		console.log(event.target.toString());
	},
});

suite.add('disable cache', {
	defer: true,
	fn(deferred) {
		const env = {
			...process.env,
			DISABLE_V8_COMPILE_CACHE: '1',
		};

		cp.execFile('node', cmdArgs, { cwd, env }, () => deferred.resolve());
	},
	onComplete(event) {
		console.log(event.target.toString());
	},
});

suite.run({ async: true });

Environment (M1 MacBook Pro):

$ sw_vers
ProductName:		macOS
ProductVersion:		13.3.1
ProductVersionExtra:	(a)
BuildVersion:		22E772610a
$ npm version
{
  stylelint: '15.7.0',
  npm: '9.6.7',
  node: '20.2.0',
  acorn: '8.8.2',
  ada: '2.4.0',
  ares: '1.19.0',
  base64: '0.5.0',
  brotli: '1.0.9',
  cjs_module_lexer: '1.2.2',
  cldr: '43.0',
  icu: '73.1',
  llhttp: '8.1.0',
  modules: '115',
  napi: '8',
  nghttp2: '1.52.0',
  nghttp3: '0.7.0',
  ngtcp2: '0.8.1',
  openssl: '3.0.8+quic',
  simdutf: '3.2.9',
  tz: '2023c',
  undici: '5.22.0',
  unicode: '15.0',
  uv: '1.44.2',
  uvwasi: '0.0.16',
  v8: '11.3.244.8-node.9',
  zlib: '1.2.13'
}

Run:

$ node scripts/benchmark-v8-compile-cache.js
enable cache x 3.82 ops/sec ±2.97% (23 runs sampled)
disable cache x 3.73 ops/sec ±2.67% (23 runs sampled)
Fastest is "enable cache"

As a result, I found out that there are almost no differences on the latest Node.js 20.2.0.

EDIT: This benchmark uses the DISABLE_V8_COMPILE_CACHE environment variable.

@ybiquitous ybiquitous added status: wip is being worked on by someone type: refactor an improvement to the code structure and removed status: needs discussion triage needs further discussion labels Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: wip is being worked on by someone type: refactor an improvement to the code structure
Development

Successfully merging a pull request may close this issue.

1 participant