Repository navigation
perf: keep requests off the main thread for type-filtered and observer-only webRequest listeners - #53204
Conversation
…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.
…ests on the direct path
e0daace to
e96aa51
Compare
|
Proposed a cleanup in #53216 |
|
thanks, pulled it in as 6ce8ae3. reran the table with it: observer-only under the busy main process 55 -> 50 ms, the frame-typed and unfiltered rows unchanged, and the new specs pass here too. |
|
Release Notes Persisted
|
|
I was unable to backport this PR to "42-x-y" cleanly; |
|
I was unable to backport this PR to "43-x-y" cleanly; |
|
I have automatically backported this PR to "44-x-y", please check out #53240 |
Description of Change
Renderer requests no longer wait for the main process when the only
webRequestlisteners that could match them are observers (onCompleted,onErrorOccurred,onSendHeaders,onBeforeRedirect,onResponseStarted) or are filtered to other resource types. Follow-up to #53115, whose IO-thread gate sent every request through the UI-threadProxyingURLLoaderFactoryas soon as a session had any listener, because a listener may modify the request and re-runs on each redirect leg, so its URL filter cannot be applied up front. Two things can be decided up front:typesfilter is honored before the request reaches the UI thread, in the gate and in the proxy's pass-through path. A blocking listener registered withtypes: ['mainFrame', 'subFrame']no longer pulls images, scripts andfetch()calls through the main process.URLLoaderClienton the IO thread reports the redirect, response and completion toapi::WebRequestafterwards. Listeners receive the samedetails(including oneonSendHeadersper redirect leg); the renderer never waits for them.InterceptStatekeeps two resource-type masks (blocking / observing) instead of a boolean, recomputed whenever a listener is added or removed.Linux x64 release, page with 150 small subresources from a local server in a separate process, median of 3 warm loads; "busy" = the main process runs 100 ms of JavaScript right after the navigation commits. Before -> after:
fetch()round triponCompleted+onErrorOccurred+onSendHeadersonBeforeRequest+onHeadersReceived,types: ['mainFrame', 'subFrame']onBeforeSendHeaders, no filterIn the 108 ms rows the subresources are on the direct path but the document request itself matches the frame-typed blocking listeners, so its completion still goes through the main process; an unfiltered blocking listener is unchanged by design.
Checklist
npm testpasses (new cases in api-web-request-spec; webRequest, protocol, session, net, webContents, subframe, webview, service worker and extensions specs locally on Linux)Release Notes
Notes: Renderer network requests no longer waited on the main process when the session's
webRequestlisteners only observe requests (onCompleted,onErrorOccurred,onSendHeaders,onBeforeRedirect,onResponseStarted) or are filtered to other resource types.