Visitar URL original
perf: keep requests off the main thread for type-filtered and observer-only webRequest listeners by trop[bot] · Pull Request #53240 · electron/electron · GitHub
Skip to content

perf: keep requests off the main thread for type-filtered and observer-only webRequest listeners - #53240

Merged
MarshallOfSound merged 3 commits into
44-x-yfrom
trop/44-x-y-bp-perf-keep-requests-off-the-main-thread-for-type-filtered-and-observer-only-webrequest-listeners-1787865687795
Aug 28, 2026
Merged

MarshallOfSound merged 3 commits into
44-x-yfrom
trop/44-x-y-bp-perf-keep-requests-off-the-main-thread-for-type-filtered-and-observer-only-webrequest-listeners-1787865687795

Conversation

@trop

@trop trop Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Backport of #53204

See that PR for details.

Notes: Renderer network requests no longer waited on the main process when the session's webRequest listeners only observe requests (onCompleted, onErrorOccurred, onSendHeaders, onBeforeRedirect, onResponseStarted) or are filtered to other resource types.

trop Bot and others added 3 commits August 27, 2026 21:21
…r-only webRequest listeners

The IO-thread gate from #53115 sent every renderer request through the
UI-thread ProxyingURLLoaderFactory as soon as the session had any
webRequest listener, and the proxy itself wrapped every request in an
InProgressRequest for the same reason: a listener may modify the
request and re-runs on every redirect leg, so its URL filter cannot be
applied up front. Two things can be decided up front though:

- A request's resource type never changes across redirects, so the
  listeners' existing `types` filter is honored before the request
  reaches the UI thread: a blocking listener (onBeforeRequest,
  onBeforeSendHeaders, onHeadersReceived) registered with
  types: ['mainFrame', 'subFrame'] no longer pulls images, scripts and
  fetches through the main process.
- onSendHeaders, onBeforeRedirect, onResponseStarted, onCompleted and
  onErrorOccurred cannot change anything. When only such listeners
  match a request's type, it goes straight to the network service and a
  pass-through URLLoaderClient on the IO thread reports the redirect,
  response and completion to api::WebRequest afterwards; the listeners
  get the same details objects (including onSendHeaders per redirect
  leg), the renderer never waits for them.

InterceptState holds two resource-type masks instead of a boolean,
recomputed whenever a listener is added or removed, and both the gate
and the proxy's pass-through path consult them. Linux x64, page with
150 subresources from a local server while the main process is busy for
100 ms after commit: onCompleted + onErrorOccurred listeners 160 -> 55
ms (no listeners: 54 ms); fetch() round trip 0.59 -> 0.46 ms; main
process CPU per request 335 -> 244 us. With onBeforeRequest /
onHeadersReceived limited to frame types, subresources take the direct
path as well (fetch 0.61 -> 0.42 ms, 321 -> 133 us per request); the
document itself is still intercepted, so that page's load event lands
at 108 ms under the same load.

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
…ests on the direct path

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
@trop
trop Bot requested a review from codebytere August 27, 2026 21:21
@trop trop Bot added 44-x-y backport This is a backport PR semver/patch backwards-compatible bug fixes labels Aug 27, 2026
@MarshallOfSound
MarshallOfSound merged commit 539b075 into 44-x-y Aug 28, 2026
91 checks passed
@release-clerk

release-clerk Bot commented Aug 28, 2026

Copy link
Copy Markdown

Release Notes Persisted

Renderer network requests no longer waited on the main process when the session's webRequest listeners only observe requests (onCompleted, onErrorOccurred, onSendHeaders, onBeforeRedirect, onResponseStarted) or are filtered to other resource types.

@MarshallOfSound
MarshallOfSound deleted the trop/44-x-y-bp-perf-keep-requests-off-the-main-thread-for-type-filtered-and-observer-only-webrequest-listeners-1787865687795 branch August 28, 2026 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

44-x-y backport This is a backport PR semver/patch backwards-compatible bug fixes

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants