#55438: perf: reuse one file: URL loader factory per session in net.fetch()
Description of Change
Every net.fetch() of a file: URL builds a new AsarURLLoaderFactory, plus a new webRequest and protocol interception proxy in front of it. This PR builds that once per session and reuses it. The proxy already looks up interceptors and webRequest listeners per request, so ones added or removed after the first fetch still apply. There are new specs for that.
This is one of three independent PRs that speed up protocol.handle() handlers that serve local files with net.fetch(), which is how VS Code serves vscode-file: (microsoft/vscode#341401). #55437 does most of the work by answering local file: fetches without the URL loader, so once it's in, most of VS Code's requests skip the code this PR changes. This one still speeds up the file: fetches that #55437 hands to the loader, such as asar paths and Range requests. #55439 is the third.
| VS Code workbench load | main |
this PR | all three PRs |
|---|---|---|---|
| with VS Code's webRequest listeners | 2694 ms | 2363 ms (−12%) | 1164 ms (−57%) |
| without listeners | 1880 ms | 1579 ms (−16%) | 1110 ms (−41%) |
Medians of 10 interleaved runs on Linux with a non-official release build, replaying VS Code's workbench load: 4,831 requests through VS Code's own vscode-file: handler. The full benchmark notes, written for agents, are here.
Checklist
- I have built and tested this change
- I have filled out the PR description
- I have reviewed and verified the changes
- tests are changed or added
- PR release notes describe the change in a way relevant to app developers, and are capitalized, punctuated, past tense, and no longer than 80 characters.
🤖 Generated with Claude Code
Release Notes
Notes: Improved performance of repeated net.fetch() calls for file: URLs.
Backports
Semver Impact
Semantic Versioning helps users understand the impact of updates:
- Major (X.y.z): Breaking changes that may require code modifications
- Minor (x.Y.z): New features that maintain backward compatibility
- Patch (x.y.Z): Bug fixes that don't change the API
- None: Changes that don't affect using facing parts of Electron