Conversation
|
Tagging subscribers to this area: @agocke, @jeffschwMSFT, @elinor-fung |
There was a problem hiding this comment.
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
priorityfield to AssetEntryInternal for potential future priority-based download handling - Refactored
fetchWasmtofetchMainWasmand restructured throttling logic with newenterThrottling()andleaveThrottling()helper functions - Split old
noThrottleNoRetrymap intonoRetry(for disabling retries) andnoBuffer(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(); |
There was a problem hiding this comment.
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.
| leaveThrottling(); | |
| if (!noBuffer[asset.behavior]) { | |
| leaveThrottling(); | |
| } |
| // 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) { |
There was a problem hiding this comment.
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.
| while (throttlingPCS && !asset.priority) { | |
| while (throttlingPCS) { |
| * Managed assembly packaged as Webcil v 1.0 | ||
| */ | ||
| | "webcil10" | ||
| | "webcil" |
There was a problem hiding this comment.
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.
leaveThrottling();after instantiation for some of themasset.priorityfor later useonDownloadedAsset();is counted even when it fails