Skip to content

perf: trim GTK and FontConfig work off the linux startup path - #53070

Merged
MarshallOfSound merged 2 commits into
mainfrom
perf/linux-toolkit-startup
Aug 22, 2026
Merged

MarshallOfSound merged 2 commits into
mainfrom
perf/linux-toolkit-startup

Conversation

@codebytere

Copy link
Copy Markdown
Member

Description of Change

Linux app launch to ready drops ~35 ms and launch to first contentful paint ~55 ms (release build, X11, medians of 25-30 interleaved cold launches per side), from two independent main-thread costs during toolkit initialization. Two commits:

what launch -> app ready launch -> first contentful paint
1 skip GDK's OpenGL probe during gtk_init() 395.7 -> 366.7 ms (-29 ms, p=9e-14) 618.0 -> 573.7 ms (-44 ms)
2 start loading FontConfig before the browser thread pool runs 393.9 -> 388.1 ms (-5.8 ms, p=7e-8) 532.0 -> 520.5 ms (-11.5 ms)

(Row 2 was measured on a lower-variance base than row 1, hence the different absolute numbers; new BrowserWindow and everything after first paint are unchanged in both.)

1. GDK GL probe. When GTK initializes inside ui::GetDefaultLinuxUi(), GDK probes the display for GLX/EGL support (gdk_x11_screen_init_gl -> epoxy -> glXQueryServerString), which dlopen()s the GL driver into the browser process on the main thread. Electron only uses GTK for theme colors (cairo) and native dialogs, none of which touch GdkGLContext, so the probe is pure cost: here it was 27 of the 68 ms between "JS modules loaded" and ready, and the driver mappings also stay resident in the browser for the life of the app. GDK reads GDK_GL exactly once during gtk_init(), so ToolkitInitialized() sets GDK_GL=disable around that call when the user has not set it and removes it again immediately after, before any app code can spawn children. The same change is proposed for Chromium's GtkUi (https://crrev.com/c/8265951); this is the Electron-side form until that lands and covers Electron's own call site either way.

2. FontConfig warm-up. content already tries to initialize FontConfig off the main thread (gfx::InitializeFonts() from BrowserMainRunnerImpl::Initialize()), but that task is posted after BrowserMainLoop raises the ThreadPool execution fence, so it can never run before the toolkit's first font lookup does FcInit + config parsing on the main thread. ElectronMainDelegate::PreBrowserMain() runs after the pool is created and before it is started and fenced, so calling gfx::InitializeGlobalFontConfigAsync() there queues the work to start with the pool and overlap toolkit init; if it ever loses the race it degrades to today's behaviour, and the later content call is a no-op on the NoDestructor singleton. Upstream review of the equivalent content change asked for exactly this placement in the embedder (https://crrev.com/c/8264864).

Both are BUILDFLAG(IS_LINUX) only; macOS and Windows are untouched.

Checklist

Release Notes

Notes: Improved application startup time on Linux by skipping GDK's OpenGL probe and loading FontConfig off the main thread during toolkit initialization.

@codebytere codebytere added semver/patch backwards-compatible bug fixes 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. target/44-x-y PR should also be added to the "44-x-y" branch. labels Aug 21, 2026
@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Aug 21, 2026

@deepak1556 deepak1556 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Upstream CL skips the GDK_GL probe for gtk 4 (which we do support as well ?), any reason to not align here ?

@codebytere
codebytere force-pushed the perf/linux-toolkit-startup branch from 7231c66 to 27ae2e1 Compare August 21, 2026 11:02
@codebytere

Copy link
Copy Markdown
Member Author

upstream can branch on the version because it runs after LoadGtk(); here the library isn't picked until inside GetDefaultLinuxUi(), so at the point we set the variable there is nothing to check yet. it comes out the same in practice: GDK_GL only exists in gtk3 - gtk4 replaced it with GDK_DEBUG=gl-disable / GDK_DISABLE=gl and libgtk-4 doesn't contain the string at all - so on a gtk4 load it is set and unset around init without gtk ever reading it. gtk4 is left alone on purpose in both places, since gsk renders its own windows (our file dialogs) with GL and turning that off would be a behaviour change rather than skipping an unused probe. pushed a comment tweak so the gtk3-only part is visible in the code.

@codebytere
codebytere force-pushed the perf/linux-toolkit-startup branch from 27ae2e1 to 5b4db80 Compare August 21, 2026 11:10
@MarshallOfSound
MarshallOfSound merged commit 86ca0d9 into main Aug 22, 2026
73 checks passed
@release-clerk

release-clerk Bot commented Aug 22, 2026

Copy link
Copy Markdown

Release Notes Persisted

Improved application startup time on Linux by skipping GDK's OpenGL probe and loading FontConfig off the main thread during toolkit initialization.

@MarshallOfSound
MarshallOfSound deleted the perf/linux-toolkit-startup branch August 22, 2026 06:04
@trop

trop Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

I was unable to backport this PR to "42-x-y" cleanly;
you will need to perform this backport manually.

@trop

trop Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

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

@trop

trop Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

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

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

Labels

45-x-y merged/43-x-y PR was merged to the "43-x-y" branch. merged/44-x-y PR was merged to the "44-x-y" branch. new-pr 🌱 PR opened recently semver/patch backwards-compatible bug fixes

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants