Skip to content

Commit ba551d2

Browse files
trop[bot]MarshallOfSoundpatchup[bot]
authored
perf: enable V8 builtins PGO (#50574)
* build: enable V8 builtins PGO Removes the gn arg that disabled V8 builtins profile-guided optimization and adds a V8 patch to warn instead of abort when the builtin PGO profile data does not match. Also strips the PGO-related flags from the generated mksnapshot_args so they are not passed through to downstream mksnapshot invocations. Co-authored-by: Sam Attard <sattard@anthropic.com> * docs: clarify Node.js async_hooks as reason for promise_hooks flag Addresses review feedback: the v8_enable_javascript_promise_hooks flag is set to support Node.js async_hooks, not used directly by Electron. Co-authored-by: Sam Attard <sattard@anthropic.com> * chore: update patches --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Sam Attard <sattard@anthropic.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
1 parent 24784ed commit ba551d2

4 files changed

Lines changed: 39 additions & 3 deletions

File tree

.github/actions/build-electron/action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ runs:
125125
fi
126126
sed $SEDOPTION '/.*builtins-pgo/d' out/Default/mksnapshot_args
127127
sed $SEDOPTION '/--turbo-profiling-input/d' out/Default/mksnapshot_args
128+
sed $SEDOPTION '/--reorder-builtins/d' out/Default/mksnapshot_args
129+
sed $SEDOPTION '/--warn-about-builtin-profile-data/d' out/Default/mksnapshot_args
130+
sed $SEDOPTION '/--abort-on-bad-builtin-profile-data/d' out/Default/mksnapshot_args
128131
129132
if [ "${{ inputs.target-platform }}" = "win" ]; then
130133
cd out/Default

build/args/all.gn

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ is_cfi = false
5151
use_qt5 = false
5252
use_qt6 = false
5353

54-
# Disables the builtins PGO for V8
55-
v8_builtins_profiling_log_file = ""
56-
5754
# https://chromium.googlesource.com/chromium/src/+/main/docs/dangling_ptr.md
5855
# TODO(vertedinde): hunt down dangling pointers on Linux
5956
enable_dangling_raw_ptr_checks = false

patches/v8/.patches

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
chore_allow_customizing_microtask_policy_per_context.patch
2+
build_warn_instead_of_abort_on_builtin_pgo_profile_mismatch.patch
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Sam Attard <sattard@anthropic.com>
3+
Date: Sun, 22 Mar 2026 10:51:26 +0000
4+
Subject: build: warn instead of abort on builtin PGO profile mismatch
5+
6+
Electron sets v8_enable_javascript_promise_hooks = true to support
7+
Node.js async_hooks (see node/src/env.cc SetPromiseHooks usage:
8+
https://github.com/nodejs/node/blob/abff716eaccd0c4f4949d1315cb057a45979649d/src/env.cc#L223-L236).
9+
This flag adds conditional branches to builtins-microtask-queue-gen.cc
10+
and promise-misc.tq, changing the control-flow graph hash of several
11+
Promise/async builtins. This invalidates V8's pre-generated PGO profile
12+
for those builtins (built with Chrome defaults where the flag is off).
13+
14+
Rather than disabling builtins PGO entirely, warn and skip mismatched
15+
builtins so all other builtins still benefit from PGO.
16+
17+
diff --git a/BUILD.gn b/BUILD.gn
18+
index 15de2179a0e5ce50d5c659a9d15a920c50124c3e..9fb3a69450bdcab42c2571e8b1f57c4f3c283d9a 100644
19+
--- a/BUILD.gn
20+
+++ b/BUILD.gn
21+
@@ -2764,9 +2764,11 @@ template("run_mksnapshot") {
22+
"--turbo-profiling-input",
23+
rebase_path(v8_builtins_profiling_log_file, root_build_dir),
24+
25+
- # Replace this with --warn-about-builtin-profile-data to see the full
26+
- # list of builtins with incompatible profiles.
27+
- "--abort-on-bad-builtin-profile-data",
28+
+ # Electron: Use warn instead of abort so that builtins whose control
29+
+ # flow is changed by Electron's build flags (e.g. RunMicrotasks via
30+
+ # v8_enable_javascript_promise_hooks) are skipped rather than failing
31+
+ # the build. All other builtins still receive PGO.
32+
+ "--warn-about-builtin-profile-data",
33+
]
34+
35+
if (!v8_enable_builtins_profiling && v8_enable_builtins_reordering) {

0 commit comments

Comments
 (0)