Skip to content

[browser] throttling#124969

Draft
pavelsavara wants to merge 2 commits intodotnet:mainfrom
pavelsavara:improve_throttling
Draft

[browser] throttling#124969
pavelsavara wants to merge 2 commits intodotnet:mainfrom
pavelsavara:improve_throttling

Conversation

@pavelsavara
Copy link
Member

@pavelsavara pavelsavara commented Feb 27, 2026

  • enable throttling for all file types.
  • leaveThrottling(); after instantiation for some of them
  • add optional asset.priority for later use
  • make sure that onDownloadedAsset(); is counted even when it fails
  • fix webcil name

@pavelsavara pavelsavara added this to the 11.0.0 milestone Feb 27, 2026
@pavelsavara pavelsavara self-assigned this Feb 27, 2026
Copilot AI review requested due to automatic review settings February 27, 2026 14:24
@pavelsavara pavelsavara added arch-wasm WebAssembly architecture area-Host os-browser Browser variant of arch-wasm labels Feb 27, 2026
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @agocke, @jeffschwMSFT, @elinor-fung
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request refactors the download throttling mechanism in the browser WASM loader. The main changes include renaming the "webcil10" asset behavior to "webcil", splitting the old noThrottleNoRetry map into separate noRetry and noBuffer maps, and restructuring throttling logic to better handle assets that don't buffer immediately (such as dotnetwasm, webcil, and symbols).

Changes:

  • Renamed "webcil10" to "webcil" (breaking API change) in public-api.ts and dotnet.d.ts
  • Added priority field to AssetEntryInternal for potential future priority-based download handling
  • Refactored fetchWasm to fetchMainWasm and restructured throttling logic with new enterThrottling() and leaveThrottling() helper functions
  • Split old noThrottleNoRetry map into noRetry (for disabling retries) and noBuffer (for skipping immediate buffering)
  • Added try-finally blocks to fetch functions for better error handling and resource cleanup

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/native/libs/Common/JavaScript/types/public-api.ts Renamed "webcil10" to "webcil" in AssetBehaviors type (breaking change)
src/native/libs/Common/JavaScript/types/internal.ts Added optional priority field to AssetEntryInternal for throttling bypass
src/native/libs/Common/JavaScript/loader/run.ts Updated import and call from fetchWasm to fetchMainWasm
src/native/libs/Common/JavaScript/loader/dotnet.d.ts Renamed "webcil10" to "webcil" in type definitions (breaking change)
src/native/libs/Common/JavaScript/loader/assets.ts Major refactoring: renamed fetchWasm to fetchMainWasm, extracted enterThrottling/leaveThrottling helpers, split noThrottleNoRetry into noRetry and noBuffer maps, added try-finally blocks for error handling, and updated webcil10 references to webcil

throttlingPCS = undefined;
oldThrottlingPCS.resolve();
}
leaveThrottling();
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Critical bug: leaveThrottling() is being called unconditionally here for all assets, but it's also called again for noBuffer assets (dotnetwasm, symbols, webcil) when their response bodies are consumed later. This causes double-decrement of currentParallelDownloads:

  • dotnetwasm: decremented here, then again in instantiateMainWasm (line 77)
  • webcil: decremented here, then again in fetchDll (line 128)
  • symbols: decremented here, then again in fetchNativeSymbols (line 283)

This will make the throttling counter incorrect and potentially negative. The fix is to only call leaveThrottling() here if !noBuffer[asset.behavior], so that noBuffer assets can leave throttling when their response body is actually consumed.

Suggested change
leaveThrottling();
if (!noBuffer[asset.behavior]) {
leaveThrottling();
}

Copilot uses AI. Check for mistakes.
// in order to prevent net::ERR_INSUFFICIENT_RESOURCES if we start downloading too many files at same time on a device with low resources
async function loadResourceThrottle(asset: AssetEntryInternal): Promise<Response> {
while (throttlingPCS) {
while (throttlingPCS && !asset.priority) {
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The priority field is checked here to allow priority assets to bypass throttling, but this field is never actually set anywhere in the codebase. This means the priority bypass feature is not functional. Either remove this check or add logic to set priority on relevant assets.

Suggested change
while (throttlingPCS && !asset.priority) {
while (throttlingPCS) {

Copilot uses AI. Check for mistakes.
* Managed assembly packaged as Webcil v 1.0
*/
| "webcil10"
| "webcil"
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking API change. Renaming "webcil10" to "webcil" will break any code that references the "webcil10" value. If this is intentional (e.g., part of a major version update), ensure this breaking change is documented. If backward compatibility is needed, consider keeping "webcil10" as an alias or documenting a migration path.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-Host os-browser Browser variant of arch-wasm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants