Repository navigation
[browser] Bundle composite R2R WebCIL IL components into a single module - #137713
Open
davidwrighton wants to merge 6 commits into
Open
davidwrighton wants to merge 6 commits into
davidwrighton wants to merge 6 commits into
Conversation
Emit a single IL component bundle, register per-assembly views in browser and corerun hosts, and integrate default-on bundling with lazy assembly validation and incremental publishing. Co-authored-by: Copilot <[email protected]>
|
Azure Pipelines: Successfully started running 4 pipeline(s). 11 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
This was referenced Nov 17, 2026
- Drop MSBuild task output metadata from the build-time bundle asset so AttachWebcilSizes reads the bundle rather than the project file. - Skip publish boot JSON generation in the nested publish; it otherwise writes an incomplete boot config and stamp that the outer publish reuses. - Avoid escaped quotes when writing the crossgen2 bundle option in generated runtime test scripts. - Wasm.Build.Tests: accept fingerprinted files whose superseded version was removed, and assert composite R2R output for partial-profile publish. Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Default-on bundling spans compiler, SDK publishing and cleanup, and browser-host contracts, requiring human validation of unverified post-rebase browser, incremental mode-switch, and Windows-wrapper paths.
No open issues 🎉
What changed in this PR
This PR bundles browser CoreCLR composite ReadyToRun IL components into one WebCIL module, reducing startup requests and module instantiations. It connects crossgen2 output with browser loading, SDK publishing, and runtime tests while preserving WASI’s existing component flow.
Changes:
- Adds the bundle format, crossgen2 option, and payload-only component emission.
- Registers bundled assemblies without copying their images and exposes individual byte copies for tooling.
- Enables bundling by default for browser composite publishing, with incremental tracking, opt-out, lazy-loading safeguards, and regression coverage.
| File | Description |
|---|---|
src/tests/Loader/TrustedPlatformAssembliesProperty/TrustedPlatformAssemblies.cs |
Checks browser ReadyToRun assembly location behavior. |
src/tests/Loader/ExternalAssemblyProbe/ExternalAssemblyProbe.cs |
Adds browser external-probe coverage. |
src/tests/Common/CLRTest.CrossGen.targets |
Generates and stages bundles for composite runtime tests. |
src/tasks/Microsoft.NET.WebAssembly.Webcil/WebcilWasmWrapper.cs |
Corrects payload alignment across encoded-length boundaries. |
src/tasks/Microsoft.NET.WebAssembly.Webcil/WebcilReader.cs |
Resets the stream before reading unwrapped payloads. |
src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/WebcilBundleReader.cs |
Validates bundles and matches component assembly identifiers. |
src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs |
Classifies bundle assets in boot configuration. |
src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/FilterWebcilBundleComponents.cs |
Filters bundled assemblies from standalone asset candidates. |
src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ConvertDllsToWebCil.cs |
Skips bundled components and validates separate lazy images. |
src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/CompositeLazyAssemblies.cs |
Excludes lazy assemblies and rejects direct composite references. |
src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonData.cs |
Adds the boot asset bundle flag. |
src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonBuilderHelper.cs |
Propagates bundle flags into generated assets. |
src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets |
Passes composite-specific compiler arguments. |
src/native/libs/Common/JavaScript/types/public-api.ts |
Describes bundle assets in public TypeScript types. |
src/native/libs/Common/JavaScript/types/internal.ts |
Adds internal bundle asset metadata. |
src/native/libs/Common/JavaScript/loader/assets.ts |
Forwards bundle metadata and preserves bundle paths. |
src/native/libs/Common/JavaScript/host/index.ts |
Exposes loaded assembly byte retrieval. |
src/native/libs/Common/JavaScript/host/host.ts |
Includes bundle entries in trusted assembly paths. |
src/native/libs/Common/JavaScript/host/assets.ts |
Validates and registers bundle views; returns byte copies. |
src/mono/wasm/Wasm.Build.Tests/WebcilInWasmSizesTests.cs |
Covers alignment, bundle validation, and lazy-reference checks. |
src/mono/wasm/Wasm.Build.Tests/Wasm.Build.Tests.csproj |
References ReadyToRun inspection helpers. |
src/mono/wasm/Wasm.Build.Tests/SatelliteLoadingTests.cs |
Exercises satellite loading with composite bundles. |
src/mono/wasm/Wasm.Build.Tests/ReadyToRunTests.cs |
Covers publishing, incremental rebuilds, mode switches, and execution. |
src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs |
Updates fingerprint tracking and bundle-aware boot assertions. |
src/mono/wasm/Wasm.Build.Tests/LazyLoadingTests.cs |
Verifies separate lazy images and invalid-reference rejection. |
src/mono/wasm/Wasm.Build.Tests/DebugLevelTests.cs |
Checks stack-trace source information with bundles. |
src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets |
Stages bundle assets and tracks publish cleanup. |
src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.CoreCLR.targets |
Enables bundling and manages exclusions and rebuild invalidation. |
src/mono/browser/build/BrowserWasmApp.CoreCLR.targets |
Returns bundle outputs from nested publishing. |
src/coreclr/tools/Common/Compiler/ObjectWriter/WebCilObjectWriter.cs |
Adds payload-only emission for bundled components. |
src/coreclr/tools/Common/Compiler/ObjectWriter/WebcilBundleWriter.cs |
Writes aligned component images into a single wrapper. |
src/coreclr/tools/Common/Compiler/ObjectWriter/Wasm/WebcilPayloadDataSegment.cs |
Separates raw payload emission from segment encoding. |
src/coreclr/tools/aot/ILCompiler.ReadyToRun/ILCompiler.ReadyToRun.csproj |
Includes bundle-writing and wrapper sources. |
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilationBuilder.cs |
Carries the bundle output setting into compilation. |
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilation.cs |
Collects rewritten component payloads into the bundle. |
src/coreclr/tools/aot/crossgen2/Properties/Resources.resx |
Adds bundle option help and validation messages. |
src/coreclr/tools/aot/crossgen2/Program.cs |
Validates bundle mode and output path collisions. |
src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs |
Registers the bundle command-line option. |
src/coreclr/hosts/corerun/wasm/libCorerun.js |
Discovers, installs, and probes bundled assemblies. |
src/coreclr/hosts/corerun/corerun.cpp |
Integrates bundle paths into browser assembly resolution. |
docs/design/mono/webcil.md |
Documents the bundle layout and loading contract. |
Review effort: Balanced
davidwrighton
marked this pull request as ready for review
November 17, 2026 22:03
davidwrighton
requested review from
MichalStrehovsky,
akoeplinger,
ilonatommy,
lewing and
maraf
as code owners
November 17, 2026 22:03
Contributor
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
pavelsavara
self-requested a review
November 18, 2026 09:52
…datedWebCIL_ILBinarySupport Resolve the Crossgen2 task invocation conflict by keeping main's instruction-set arguments and the composite-only argument plumbing. Make the composite argument property private (_PublishReadyToRunCrossgen2CompositeExtraArgs) and include it in the ReadyToRun compiler-argument fingerprint. Co-authored-by: Copilot <[email protected]> Copilot-Session: 96e51893-de9d-4081-a1ad-dc7f5ed33991
maraf
reviewed
Nov 19, 2026
Co-authored-by: Copilot <[email protected]>
maraf
reviewed
Nov 20, 2026
Rely on ReadyToRun output tracking for the composite bundle instead of invalidating the owner image through a separate target. Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
This branch has not been deployed
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.
Summary
Browser CoreCLR composite ReadyToRun publishing currently produces one runtime module, one composite R2R code module, and a separate self-installing WebCIL module for every IL assembly (~65 for the Havit Blazor documentation app). Each of those IL modules is fetched, compiled, and instantiated individually during startup.
This change makes crossgen2 package all composite IL components into one WebCIL wrapper (
<app>.components.wasm), which the host instantiates once. A normal browser composite publish now loads two compiler-produced modules: the R2R code module and the IL bundle.Changes
docs/design/mono/webcil.md): a version 2 self-installing wrapper (tableSize0) whose payload is aWbIBbundle. It has a header, a directory, and a name table, followed by 16-byte-aligned, independent WebCIL v1 component images.--webcil-component-bundle:<path>option. In composite WebCIL mode it writes the component images into a single bundle (WebcilBundleWriter) instead of one wrapper per assembly. Default output without the option is unchanged.src/native/libs/Common/JavaScript/host): the boot asset is markedisWebcilBundle. The host instantiates it once into one aligned allocation and validates the directory. It then registers each image as an(address, size)view in the TPA without copying.INTERNAL.getLoadedAssemblyBytes(path)returns a copy of a single assembly view for consumers such as debugger tooling.WasmBundleCompositeComponents=false.BlazorWebAssemblyLazyLoad) are excluded from the composite and compiled as non-composite R2R. Publishing fails if a composite assembly references a lazy assembly directly (CompositeLazyAssemblies), because composite images assume all of their component IL is present together.WebcilBundleReaderlets pack tasks read the bundle's entries.src/tests/Common/CLRTest.CrossGen.targetsstages the bundle for browser composite runtime tests.WebcilInWasmSizesTests). Also browser execution, incremental publish, opt-out, mode switches, workload relink with wasm-opt, lazy loading, satellites, and debug levels.Measurements (Havit Blazor documentation, local headless Chrome)
Median time to reach managed code; 10 cold and 5 warm runs; same source revision:
Cold requests fell from 97 to 33 and cold transfer from about 9.00 MB to 8.78 MB. Startup-instantiated Wasm modules went from 67 to 3. Resource satellites remain separate.
Validation
./build.sh clr.native+clr.tools+host.native -os browser -arch wasm -c Release /p:RuntimeFlavor=CoreCLR: passed../build.sh tasks -c Release: passed../dotnet.sh build src/mono/wasm/Wasm.Build.Tests/Wasm.Build.Tests.csproj -c Release -t:Test -p:TargetOS=browser -p:TargetArchitecture=wasm -p:RuntimeFlavor=CoreCLR -p:TestUsingWorkloads=false -p:XUnitClassName=Wasm.Build.Tests.WebcilInWasmSizesTests: 33 passed, 0 failed (after rebasing onto currentmain).Known limitations / follow-ups
AdditionalOutputscontract; the runtime targets and in-treeCrossgen2Tasksshim still need to set the bundle as an extra output. Until that support reaches the stock SDK, a missing bundle by itself may not trigger a rebuild in the explicit stock-SDK path. The browser composite bundle has not shipped, so this temporary gap is not a shipped-version compatibility constraint.getLoadedAssemblyBytesexposes per-assembly bytes, but no CoreCLR browser debugger consumer has been integrated yet.Note
This PR description was generated with GitHub Copilot.