Repository navigation
perf: stop routing renderer requests and file loads through the main thread - #53141
Merged
Merged
Conversation
4 tasks done
codebytere
enabled auto-merge (squash)
August 24, 2026 20:01
…thread (#53115) * perf: keep renderer network requests off the main thread unless they are observed Every URLLoaderFactory handed to a renderer was wrapped in a ProxyingURLLoaderFactory living on the UI thread, so each subresource request took a detour through the browser's main thread even when no webRequest listener or intercepted protocol existed, and waited there behind whatever JavaScript the app was running. A page with 150 small subresources loads in 51 ms with an idle main process and 152 ms when the main process is busy for 100 ms after commit. Put a small gate on the IO thread in front of the proxy for renderer-facing factories: it forwards straight to the network service unless the session currently has a webRequest listener, an intercepted scheme matching the request, or an --ignore-connections-limit domain, in which case the request goes to the proxy exactly as before. The state is a few words under a lock, written by api::WebRequest and ProtocolRegistry when listeners or handlers change, so adding a listener takes effect for the next request without recreating factories. Same page: 46 ms idle, 51 ms with the busy main process; fetch() round trip 0.43 -> 0.41 ms. * perf: bind the file:// URL loader factory off the main thread AsarURLLoaderFactory (Electron's factory for file://, including paths inside asar archives) was created and bound on the UI thread, although all it does per request is post an AsarURLLoader to the thread pool. So every <script>, <link> or image a file:// page loads was dispatched via the browser's main thread and waited there behind the app's JavaScript: a page with 60 small stylesheets on disk loads in 30 ms with an idle main process, 130 ms when the main process is busy for 100 ms after the navigation commits, 230 ms for 200 ms. Bind the factory on the IO thread instead. The same page loads in 28 / 30 / 31 ms. * perf: skip the trusted-header round trips for requests proxied without webRequest listeners ProxyingURLLoaderFactory put every proxied request in "extraHeaders" mode, which makes the network service call back into this process (TrustedHeaderClient) before sending headers and after receiving them. That is what lets webRequest listeners see and modify headers the network stack owns, so it stays whenever the session has any listener; requests that reach the proxy only because a protocol is intercepted or a connection-limit domain is configured have nothing to consult there and now skip the two round trips. * perf: don't build console-message events while nothing listens for them Every console call in a renderer reached OnDidAddMessageToConsole, which created an Event, filled a dictionary and emitted into JS whether or not the app had a 'console-message' listener: 22.6 us of main-process CPU per renderer console.log here. WebContents now keeps a flag from JS (newListener / removeListener) and returns early without it: 13.4 us per message, i.e. 20,000 renderer log lines cost the main process 269 ms instead of 452. (cherry picked from commit adc50a1)
codebytere
force-pushed
the
bp/44-x-y/53115
branch
from
August 24, 2026 21:46
1fcd687 to
64914f6
Compare
MarshallOfSound
approved these changes
Aug 25, 2026
|
Release Notes Persisted
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #53115
See that PR for details. Only a member-list context conflict in electron_api_web_contents.h (44-x-y lacks the caret-browsing refcount); resolved by hand.
Notes: Page resources,
fetch()calls and file:// loads in renderers no longer wait for the main process to be idle when nowebRequestlisteners or protocol interceptors are registered.