-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
module: implement flushCompileCache() #54971
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -847,14 +847,12 @@ Environment::Environment(IsolateData* isolate_data, | |
} | ||
} | ||
|
||
// We are supposed to call builtin_loader_.SetEagerCompile() in | ||
// snapshot mode here because it's beneficial to compile built-ins | ||
// loaded in the snapshot eagerly and include the code of inner functions | ||
// that are likely to be used by user since they are part of the core | ||
// startup. But this requires us to start the coverage collections | ||
// before Environment/Context creation which is not currently possible. | ||
// TODO(joyeecheung): refactor V8ProfilerConnection classes to parse | ||
// JSON without v8 and lift this restriction. | ||
// Compile builtins eagerly when building the snapshot so that inner functions | ||
// of essential builtins that are loaded in the snapshot can have faster first | ||
// invocation. | ||
if (isolate_data->is_building_snapshot()) { | ||
builtin_loader()->SetEagerCompile(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For posterity: the short summary of this small diff that accidentally get landed in this unrelated PR is that it speeds up core startup by not having to compile any inner functions in essential builtins. Previously, only the top-level functions were cached in the snapshot, so during bootstrap, when the inner functions were executed to do the loading, they still needed to be compiled without cache. This diff changed to cache the inner functions too, which adds ~630KB to the binary, in exchange of a slightly faster core startup (and also speeding up the first invocation of most functions provided by the essential builtins).
|
||
} | ||
|
||
// We'll be creating new objects so make sure we've entered the context. | ||
HandleScope handle_scope(isolate); | ||
|
@@ -1143,7 +1141,7 @@ CompileCacheEnableResult Environment::EnableCompileCache( | |
compile_cache_handler_ = std::move(handler); | ||
AtExit( | ||
[](void* env) { | ||
static_cast<Environment*>(env)->compile_cache_handler()->Persist(); | ||
static_cast<Environment*>(env)->FlushCompileCache(); | ||
}, | ||
this); | ||
} | ||
|
@@ -1160,6 +1158,13 @@ CompileCacheEnableResult Environment::EnableCompileCache( | |
return result; | ||
} | ||
|
||
void Environment::FlushCompileCache() { | ||
if (!compile_cache_handler_ || compile_cache_handler_->cache_dir().empty()) { | ||
return; | ||
} | ||
compile_cache_handler_->Persist(); | ||
} | ||
|
||
void Environment::ExitEnv(StopFlags::Flags flags) { | ||
// Should not access non-thread-safe methods here. | ||
set_stopping(true); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
const { flushCompileCache, getCompileCacheDir } = require('module'); | ||
const { spawnSync } = require('child_process'); | ||
const assert = require('assert'); | ||
|
||
if (process.argv[2] !== 'child') { | ||
// The test should be run with the compile cache already enabled and NODE_DEBUG_NATIVE=COMPILE_CACHE. | ||
assert(getCompileCacheDir()); | ||
assert(process.env.NODE_DEBUG_NATIVE.includes('COMPILE_CACHE')); | ||
|
||
flushCompileCache(); | ||
|
||
const child1 = spawnSync(process.execPath, [__filename, 'child']); | ||
console.log(child1.stderr.toString().trim().split('\n').map(line => `[child1]${line}`).join('\n')); | ||
|
||
flushCompileCache(); | ||
|
||
const child2 = spawnSync(process.execPath, [__filename, 'child']); | ||
console.log(child2.stderr.toString().trim().split('\n').map(line => `[child2]${line}`).join('\n')); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
// This tests module.enableCompileCache() throws when an invalid argument is passed. | ||
|
||
require('../common'); | ||
const { enableCompileCache } = require('module'); | ||
const assert = require('assert'); | ||
|
||
for (const invalid of [0, null, false, () => {}, {}, []]) { | ||
assert.throws(() => enableCompileCache(invalid), { code: 'ERR_INVALID_ARG_TYPE' }); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.