Repository navigation
build: enable ThinLTO link-time optimization for the main binary - #51809
Conversation
Chromium applies the thinlto_optimize_default config to all targets by default, which passes --lto-O0 (Windows: /opt:lldlto=0) to the linker -- i.e. no optimization is performed during the ThinLTO link step. Chrome opts its main binaries (chrome executable, chrome.dll, Chrome Framework) into the thinlto_optimize_max config to get full link-time optimization, but Electron never did, so release builds of Electron were linked with --lto-O0 and lost most of the benefit of ThinLTO and PGO. Swap in thinlto_optimize_max for electron_app (Linux/Windows) and electron_framework (macOS), exactly like chrome/BUILD.gn does for its equivalent targets.
|
Release Notes Persisted
|
|
I have automatically backported this PR to "43-x-y", please check out #51820 |
|
I have automatically backported this PR to "42-x-y", please check out #51821 |
|
@MarshallOfSound this is wonderful, how about leveraging PGO builds too? in addition to LTO (and maybe BOLT like binary optimizers https://www.phoronix.com/news/Fedora-Idea-More-PGO-LLVM-BOLT |
|
@MarshallOfSound Thanks for this. |
Description of Change
Chromium's build system applies the
thinlto_optimize_defaultconfig to every target by default. That config passes--lto-O0(Windows:/opt:lldlto=0) to the linker, meaning no optimization is performed during the ThinLTO link step — it exists to keep developer links fast. Targets that want real link-time optimization must explicitly swap inthinlto_optimize_max, which Chrome does for its three main binaries (chrome_initial,chrome_dllon Windows, andchrome_frameworkon macOS).Electron has never done this swap, so every release build of Electron that uses ThinLTO (Linux and Windows today; macOS once #51669 lands) links the main binary with
--lto-O0, giving up cross-module inlining and most of the link-time benefit of PGO.This change applies the same config swap to
electron_app(Linux/Windows executable) andelectron_framework(macOS framework), exactly mirroring whatchrome/BUILD.gndoes for its equivalent targets.Performance impact (measured)
Speedometer 3.1, Linux x64 release build from
main, interleaved benchmark rounds of 10 iterations each on the same machine:--lto-O0)--lto-O2)+13.2% improvement. For reference, Chrome for Testing at the same Chromium version (150.0.7863.0) scores ~28.4 in the same environment, so this change closes roughly half of the gap between Electron release builds and Chrome.
Build cost
.textgrows ~8.4% from more aggressive cross-module inlining — the same trade-off Chrome makes for its binaries.Related
--lto-O0once ThinLTO is re-enabled there; with it, that PR delivers full link-time optimization on macOS too.Checklist
npm testpassesRelease Notes
Notes: Improved performance of Linux and Windows release builds by enabling ThinLTO link-time optimization for the main Electron binary.