Skip to content

Commit cb00db4

Browse files
Keyhan VakilV8 LUCI CQ
authored andcommitted
[compiler] fix CompileFunction ignoring kEagerCompile
v8::ScriptCompiler::CompileFunction was ignoring kEagerCompile. Unlike the other functions in v8::ScriptCompiler, it was not actually propagating kEagerCompile to the parser. The newly updated test fails without this change. I did some archeology and found that this was commented out since the original CL in https://crrev.com/c/980944. As far as I know Node.js is the main consumer of this particular API. This CL speeds up Node.js's overall startup time by ~13%. Change-Id: Ifc3cd6653555194d46ca48db14f7ba7a4afe0053 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4571822 Commit-Queue: Marja Hölttä <[email protected]> Reviewed-by: Marja Hölttä <[email protected]> Cr-Commit-Position: refs/heads/main@{#87944}
1 parent 3cc08e8 commit cb00db4

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/codegen/compiler.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3721,7 +3721,7 @@ MaybeHandle<JSFunction> Compiler::GetWrappedFunction(
37213721
// functions fully non-lazy instead thus preventing source positions from
37223722
// being omitted.
37233723
flags.set_collect_source_positions(true);
3724-
// flags.set_eager(compile_options == ScriptCompiler::kEagerCompile);
3724+
flags.set_is_eager(compile_options == ScriptCompiler::kEagerCompile);
37253725

37263726
UnoptimizedCompileState compile_state;
37273727
ReusableUnoptimizedCompileState reusable_state(isolate);

test/cctest/test-serialize.cc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4988,6 +4988,37 @@ TEST(CachedCompileFunction) {
49884988
}
49894989
}
49904990

4991+
TEST(CachedCompileFunctionRespectsEager) {
4992+
DisableAlwaysOpt();
4993+
LocalContext env;
4994+
Isolate* isolate = CcTest::i_isolate();
4995+
isolate->compilation_cache()
4996+
->DisableScriptAndEval(); // Disable same-isolate code cache.
4997+
4998+
v8::HandleScope scope(CcTest::isolate());
4999+
5000+
v8::Local<v8::String> source = v8_str("return function() { return 42; }");
5001+
v8::ScriptCompiler::Source script_source(source);
5002+
5003+
for (bool eager_compile : {false, true}) {
5004+
v8::ScriptCompiler::CompileOptions options =
5005+
eager_compile ? v8::ScriptCompiler::kEagerCompile
5006+
: v8::ScriptCompiler::kNoCompileOptions;
5007+
v8::Local<v8::Value> fun =
5008+
v8::ScriptCompiler::CompileFunction(env.local(), &script_source, 0,
5009+
nullptr, 0, nullptr, options)
5010+
.ToLocalChecked()
5011+
.As<v8::Function>()
5012+
->Call(env.local(), v8::Undefined(CcTest::isolate()), 0, nullptr)
5013+
.ToLocalChecked();
5014+
5015+
auto i_fun = i::Handle<i::JSFunction>::cast(Utils::OpenHandle(*fun));
5016+
5017+
// Function should be compiled iff kEagerCompile was used.
5018+
CHECK_EQ(i_fun->shared().is_compiled(), eager_compile);
5019+
}
5020+
}
5021+
49915022
UNINITIALIZED_TEST(SnapshotCreatorAnonClassWithKeep) {
49925023
DisableAlwaysOpt();
49935024
v8::SnapshotCreator creator;

0 commit comments

Comments
 (0)