Repository navigation
perf: relay untouched net.fetch responses from protocol.handle without pumping them through JS - #53379
Merged
Conversation
…t pumping them through JS protocol.handle(scheme, req => net.fetch(...)) is the documented way to serve an app's own files from a custom scheme and to proxy a remote origin through one, and every byte of such a response crossed the browser main thread twice: SimpleURLLoader's chunks were copied into ArrayBuffers for an IncomingMessage, wrapped into a web ReadableStream for the Response, unwrapped again with Readable.fromWeb and written back into a mojo pipe by NodeStreamLoader in 64 KB slices. When a handler returns the Response net.fetch produced with its body still untouched (the exact stream net.fetch created, not read, locked, cloned or replaced), protocol.handle now tells the underlying SimpleURLLoaderWrapper to stop handing chunks to JS, collects whatever JS had already pulled as a prefix, and passes the client end to the wrapper, which writes prefix and remainder straight into the response pipe and completes the client with the request's outcome. Status and headers of the returned Response (including ones the handler set) are used as before; anything else - a re-wrapped or re-created Response, a body the handler started reading, Response.error() - keeps the existing path. The response pipe grows to the upstream's declared length (up to the network service default) but never below mojo's default. Works for any scheme net.fetch can load. Renderer fetch() through such a handler, release build, medians of interleaved fresh-process runs: forwarding to file:// 16 MB 40.0 -> 24.1 ms, 1 MB 4.5 -> 3.8 ms, 64 KB 2.0 -> 1.9 ms; forwarding to a local http server (cache: 'no-store') 16 MB 48.2 -> 24.2 ms, 1 MB 4.0 -> 3.3 ms, 64 KB unchanged. With the HTTP cache writing the proxied body through, the cache write dominates either way (16 MB ~480 ms on this disk). Co-authored-by: Shelley Vohr <[email protected]>
…rapper Review follow-up: SimpleURLLoaderWrapper no longer tracks relay state itself. A ResponseBody object is the SimpleURLLoader stream consumer; it hands chunks to its delegate (the wrapper, which emits them to JS) until held, and once RelayTo() gives it a destination it writes the held and all further chunks into that client's data pipe and completes the client when the request completes. The wrapper keeps only the JS-facing events and request lifetime. Co-authored-by: Shelley Vohr <[email protected]>
ResponseBody::OnComplete() returned before recording the result when the body had not been held yet, so a handler that awaited between net.fetch() and returning the response handed RelayTo() a finished request with no result to complete the client with, and the load hung. Record the result unconditionally, and when JS has already drained the whole body before the relay decision, answer with that data instead of a native relay. Co-authored-by: Shelley Vohr <[email protected]>
6 tasks done
…tch-responses-from-protocol-handle-without-pumping-them-through-js-1788291929547 Co-authored-by: electron-claude[bot] <279139701+electron-claude[bot]@users.noreply.github.com> # Conflicts: # shell/common/api/electron_api_url_loader.cc # shell/common/api/electron_api_url_loader.h
Contributor
|
Claude PR Fix (run) added 1 GitHub-signed commit(s) to this branch through the Git Data API, fast-forwarding it 6ff53fe..b9d71df; no existing history was rewritten.
The new commits were produced by an automated agent (Claude) and re-created by the Electron Claude App so they carry GitHub's signature; each keeps its original author as a |
MarshallOfSound
approved these changes
Sep 3, 2026
MarshallOfSound
enabled auto-merge (squash)
September 3, 2026 17:57
codebytere
approved these changes
Sep 4, 2026
MarshallOfSound
deleted the
trop/45-x-y-bp-perf-relay-untouched-net-fetch-responses-from-protocol-handle-without-pumping-them-through-js-1788291929547
branch
September 4, 2026 06:37
|
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 #52953
See that PR for details.
Notes: Improved throughput of responses that
protocol.handlehandlers return straight fromnet.fetch.