Skip to content

build: enable ThinLTO link-time optimization for the main binary#51809

Merged
jkleinsc merged 1 commit into
mainfrom
sam/enable-thinlto-optimization
Jun 1, 2026
Merged

build: enable ThinLTO link-time optimization for the main binary#51809
jkleinsc merged 1 commit into
mainfrom
sam/enable-thinlto-optimization

Conversation

@MarshallOfSound
Copy link
Copy Markdown
Member

@MarshallOfSound MarshallOfSound commented May 30, 2026

Description of Change

Chromium's build system applies the thinlto_optimize_default config 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 in thinlto_optimize_max, which Chrome does for its three main binaries (chrome_initial, chrome_dll on Windows, and chrome_framework on 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) and electron_framework (macOS framework), exactly mirroring what chrome/BUILD.gn does 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:

Build Score
Electron release build today (--lto-O0) 22.08 ± 0.19
Electron with this change (--lto-O2) 24.99 ± 0.79

+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

  • The final ThinLTO link of the main binary becomes more expensive: observed ~8 min → ~15 min on a 64-core machine, peak link RAM ~38 GB.
  • .text grows ~8.4% from more aggressive cross-module inlining — the same trade-off Chrome makes for its binaries.
  • Component/testing builds (which don't use ThinLTO) are unaffected.

Related

  • build: re-enable ThinLTO on macOS #51669 — complementary: without this change, macOS would still link at --lto-O0 once ThinLTO is re-enabled there; with it, that PR delivers full link-time optimization on macOS too.

Checklist

Release Notes

Notes: Improved performance of Linux and Windows release builds by enabling ThinLTO link-time optimization for the main Electron binary.

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.
@MarshallOfSound MarshallOfSound added target/41-x-y PR should also be added to the "41-x-y" branch. target/42-x-y PR should also be added to the "42-x-y" branch. target/43-x-y PR should also be added to the "43-x-y" branch. and removed target/41-x-y PR should also be added to the "41-x-y" branch. labels May 30, 2026
Copy link
Copy Markdown
Member

@deepak1556 deepak1556 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find, thanks!

@jkleinsc jkleinsc merged commit 4802a7c into main Jun 1, 2026
139 of 141 checks passed
@jkleinsc jkleinsc deleted the sam/enable-thinlto-optimization branch June 1, 2026 14:23
@release-clerk
Copy link
Copy Markdown

release-clerk Bot commented Jun 1, 2026

Release Notes Persisted

Improved performance of Linux and Windows release builds by enabling ThinLTO link-time optimization for the main Electron binary.

@trop
Copy link
Copy Markdown
Contributor

trop Bot commented Jun 1, 2026

I have automatically backported this PR to "43-x-y", please check out #51820

@trop trop Bot added the in-flight/43-x-y label Jun 1, 2026
@trop
Copy link
Copy Markdown
Contributor

trop Bot commented Jun 1, 2026

I have automatically backported this PR to "42-x-y", please check out #51821

@trop trop Bot added in-flight/42-x-y merged/42-x-y PR was merged to the "42-x-y" branch. merged/43-x-y PR was merged to the "43-x-y" branch. and removed target/43-x-y PR should also be added to the "43-x-y" branch. target/42-x-y PR should also be added to the "42-x-y" branch. in-flight/42-x-y in-flight/43-x-y labels Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged/42-x-y PR was merged to the "42-x-y" branch. merged/43-x-y PR was merged to the "43-x-y" branch. semver/none

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants