Skip to content

Commit f4595bd

Browse files
kvakilanonrig
authored andcommitted
deps: V8: cherry-pick cb00db4dba6c
Original commit message: [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} Refs: v8/v8@cb00db4 PR-URL: nodejs#48671 Refs: nodejs#48576 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent 08459f5 commit f4595bd

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

deps/v8/src/codegen/compiler.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -3686,7 +3686,7 @@ MaybeHandle<JSFunction> Compiler::GetWrappedFunction(
36863686
// functions fully non-lazy instead thus preventing source positions from
36873687
// being omitted.
36883688
flags.set_collect_source_positions(true);
3689-
// flags.set_eager(compile_options == ScriptCompiler::kEagerCompile);
3689+
flags.set_is_eager(compile_options == ScriptCompiler::kEagerCompile);
36903690

36913691
UnoptimizedCompileState compile_state;
36923692
ReusableUnoptimizedCompileState reusable_state(isolate);

deps/v8/test/cctest/test-serialize.cc

+31
Original file line numberDiff line numberDiff line change
@@ -4979,6 +4979,37 @@ TEST(CachedCompileFunction) {
49794979
}
49804980
}
49814981

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

0 commit comments

Comments
 (0)