Repository navigation
[browser][coreclr] Support WasmRunWasmOpt for ReadyToRun images - #136772
Merged
Merged
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
Member
Author
|
/azp run runtime-coreclr outerloop |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
lewing
force-pushed
the
lewing-r2r-wasm-opt-prototype
branch
from
November 2, 2026 19:00
0305e97 to
10309c2
Compare
lewing
marked this pull request as ready for review
November 3, 2026 15:26
lewing
requested review from
akoeplinger,
ilonatommy and
maraf
as code owners
November 3, 2026 15:26
3 tasks
lewing
force-pushed
the
lewing-r2r-wasm-opt-prototype
branch
from
November 4, 2026 16:56
10309c2 to
d9f1d95
Compare
maraf
reviewed
Nov 6, 2026
lewing
added a commit
to dotnet/sdk
that referenced
this pull request
Nov 6, 2026
CoreCLR browser runs wasm-opt from the workload's Emscripten SDK over the relinked dotnet.native.wasm and over ReadyToRun images, so WasmRunWasmOpt=true needs the wasm-tools workload. Port the runtime change from dotnet/runtime#136772. Co-authored-by: Copilot App <[email protected]>
lewing
force-pushed
the
lewing-r2r-wasm-opt-prototype
branch
from
November 8, 2026 21:30
d9f1d95 to
b487e93
Compare
maraf
approved these changes
Nov 9, 2026
Run wasm-opt over the per-app ReadyToRun images (each per-assembly image, or the composite) after crossgen2 and before webcil staging and fingerprinting, when WasmRunWasmOpt=true. The option stays opt-in. - The pass lives in the workload's BrowserWasmApp.CoreCLR.targets, which has the Emscripten SDK's wasm-opt. The SDK pack warns when WasmRunWasmOpt is set for a ReadyToRun publish without the workload targets. - Pass the shared @(_WasmOptFeatureFlag) features; crossgen2 images carry no target_features section. - Skip memory-packing so passive data segment 0 (payloadSize/tableSize read by AttachWebcilSizes) and the payload segment stay intact. - Default to -O2, which compresses smaller than -Oz on R2R images; an -O level in WasmOptConfigurationFlags wins. Keep the name section only with WasmNativeDebugSymbols and without WasmNativeStrip. - Fold the wasm-opt settings into the R2R state stamp so toggling them recompiles, and stamp each optimized image so up-to-date images are not optimized twice. - Add PublishRunAllPagesWasmOpt (per-assembly and composite) to the wasm-opt Wasm.Build.Tests lane. Contributes to #134439 Co-authored-by: Copilot App <[email protected]>
wasm-opt re-encodes ReadyToRun images and moves the Webcil payload off the 16-byte file alignment crossgen2 gives it. R2RDump reads the payload at its file offset and rejects the NativeCuckooFilter section of an unaligned image. - Add WebcilWasmPayloadAlignment to Microsoft.NET.WebAssembly.Webcil, which re-pads passive data segment 0 so the payload starts aligned again, keeping every segment's contents. - Add the AlignWebcilPayload task and run it on each image after wasm-opt. - Always pass -g so wasm-opt keeps whatever names crossgen2 emitted; crossgen2's wasm debug-info settings decide whether there are any. - Document why -O2 is the default for R2R images. - Assert the payload alignment in PublishRunAllPagesWasmOpt. The padding costs at most 15 bytes per image. Relaxing the file-alignment rule (#133139) instead would save about 0.003% of image size and has no runtime effect, because the host aligns the payload in memory. Co-authored-by: Copilot App <[email protected]>
…ad requirement, lane tests - Resolve wasm-opt for ReadyToRun images through _CoreCLRResolveWasmOpt, shared with the relink, instead of a second lookup. - Require the browser workload when WasmRunWasmOpt=true for CoreCLR, in the workload manifest. Keep the SDK pack warning for builds that still lack the workload targets, for example UsingBrowserRuntimeWorkload=false. - Fold the dedicated ReadyToRun wasm-opt test into the wasm-opt lane: AssertReadyToRunWasmOpt checks the optimized images (stamps, payload alignment) only when the lane enables WasmRunWasmOpt, and that nothing was optimized otherwise. NativeLibraryTests.ProjectWithNativeReference_ReadyToRun covers per-assembly images; PublishRunAllPagesCompositeWithWorkload covers the composite, since no existing workload-mode test publishes one. Co-authored-by: Copilot App <[email protected]>
maraf
force-pushed
the
lewing-r2r-wasm-opt-prototype
branch
from
November 10, 2026 09:31
b487e93 to
3aa2d02
Compare
lewing
enabled stacked auto-merge (squash)
November 10, 2026 17:17
Member
Author
|
/ba-g windows wasm bad exit is known |
maraf
pushed a commit
that referenced
this pull request
Nov 11, 2026
Removes `extraBuildArgs.Add("-v:diag");` from
`ReadyToRunTests.PublishCrossgen2ArgumentsReflectWasmDebugInfoProperties`.
The theory matrix and assertions are unchanged.
## Why
The Helix work item `WBT-NoWorkload-CLR-Wasm.Build.Tests` on
`windows.server2025.amd64.open` is dead-lettering on main and on PRs.
Examples: main build 1672437, and #136772 builds 1670137 and 1672543.
Each one fails with exit -1 after 0 s and no console log.
- Helix heartbeats show each attempt runs for exactly 90 min, which is
the `_workItemTimeout` of 01:30:00. The machine then reboots and the
item retries on another machine. After 3 attempts it dead-letters.
- The median Windows duration for this work item went from about 55 min
(Nov 3–4) to about 91 min (Nov 5 onward). That change lines up with
#136506 (b0643c8, merged Nov 5). It added 12
`[TestCategory("no-workload")]` cases of this test, and each one
publishes with `-v:diag`.
- In a passing slow run (Helix job
`a5e1304b-0299-470a-a3ce-9a2289a5b925`, from #137223), `testResults.xml`
was **1.47 GB**. In a run from before #136506 (job
`e197dfa2-77e6-46f3-8c6c-b0c6903841b1`) it was **504 KB**. Each of these
cases captured about 120 MB (~1M lines) of diag MSBuild output and took
about 121 s.
The test doesn't need diagnostic verbosity.
`GetCrossgen2ExtraCommandLineArgs(binlogPath)` reads the
`Crossgen2ExtraCommandLineArgs` parameter of the `RunReadyToRunCompiler`
task from the binlog, and the binary logger records task parameters at
any console verbosity.
## Validation
- `./dotnet.sh build
src/mono/wasm/Wasm.Build.Tests/Wasm.Build.Tests.csproj -c Release
-p:TargetOS=browser -p:TargetArchitecture=wasm -p:RuntimeFlavor=CoreCLR
-p:InstallWorkloadForTesting=false`: **passed** (0 warnings, 0 errors).
- Without `-p:InstallWorkloadForTesting=false`, the test assembly still
compiled. The build then failed in the testing-SDK provisioning step
(`workloads-browser.targets(122,5)`), because this worktree has no
locally built runtime packs.
- I did **not** run the test locally, since that needs a full
browser-wasm CoreCLR build. CI coverage of the Windows
`WBT-NoWorkload-CLR` work item is the real check.
> [!NOTE]
> This PR description was generated with GitHub Copilot.
Co-authored-by: Copilot App <[email protected]>
maraf
added a commit
that referenced
this pull request
Nov 25, 2026
<!-- --> ## Summary Add focused WebAssembly review guidance based on recurring PR feedback, without expanding global repository instructions. - Put the general guide in the runtime-neutral `docs/workflow/wasm-review.md`, covering SDK/workload/in-tree ownership, configuration consumers, native build bridges, incremental outputs and Static Web Assets. - Extend the Wasm.Build.Tests README with scenario/output-helper reuse, category selection, scoped binlog observations and coverage guidance. - Add a Wasm-scoped instruction router and link the guide from the existing Wasm documentation index. Documentation only; no product code, test implementation or public API changes. ## Independent historical-review validation Four fresh sessions reviewed two merged PRs: one baseline and one new-guidance reviewer per PR. Each reviewed the exact source head attached to the original feedback, not the final merged code. Original comments, expected findings and counterpart results were withheld from reviewers; their first-pass responses were saved and hashed before comparison. | PR | Frozen pre-feedback head | Baseline agreement | New-guidance agreement | | --- | --- | --- | --- | | [#136971](#136971) | `1e6c03358c1575baaf29538bf630ab0647a16beb` | 1.5/4 | 4/4 | | [#136772](#136772) | `d9f1d954190aa89869e920bbf7b98f9324862240` | 0/3 | 2/3 | | **Total** | | **1.5/7** | **6/7** | Scoring criteria were fixed before launch: 1 for a specific actionable equivalent to the original feedback, 0.5 for an incomplete equivalent, and 0 for absent or generic advice. These measure feedback agreement, not production-defect counts. Original feedback was published by the reviewer's account; some comments explicitly disclose Copilot assistance. | Feedback criterion | Baseline | New guidance | | --- | --- | --- | | Direct MSBuild Publish default and coverage | 0 | 1 | | Proper shared testasset/scenario | 0.5 | 1 | | Standard test-output helper | 0 | 1 | | CoreCLR runtime category | 1 | 1 | | Synchronize the equivalent SDK workload-manifest condition | 0 | 0 | | Share the literal CMake feature baseline | 0 | 1 | | Respect the separate Mono CMake bridge and runtime-specific policy | 0 | 1 | The baseline asset recommendation moved the program into a replacement fixture; the guided recommendation used a shared application scenario, matching the original follow-up more closely. Both arms missed the SDK manifest synchronization. The relevant equivalent SDK gate was subsequently verified in version-pinned source, not by executing the historical SDK. Both native reviews also found the supported DLL-named R2R output being excluded by an extension filter and incomplete all-image stamp assertions; these common findings are not credited as guidance uplift. Guided output was not a strict superset: baseline-only advice included preserving the first build's binlog and adding independent alignment-rewriter regression tests. ### Limitations This is a small retrospective comparison on two cases used to derive the guidance, not a held-out, randomized or causal demonstration of general improvement. The coordinator knew the treatment arms; inherited instructions, temporally newer contributor docs, skill availability and probe use were not fully controlled. Reviewers explicitly consumed the new Markdown content, so automatic instruction-router activation was not tested. No full historical SDK/browser/toolchain scenario was reproduced, and no zero-false-positive rate is claimed. ## Validation - `git diff --check` — passed. - `npm exec --yes --package markdownlint-cli -- markdownlint .github/instructions/wasm.instructions.md docs/workflow/wasm-review.md src/mono/wasm/Wasm.Build.Tests/README.md docs/workflow/wasm-documentation.md` — passed with repository configuration. - Session-local documentation validator — passed 18 relative link/anchor checks, 14 existing positive and 8 negative routing examples, frontmatter, final newlines and trailing whitespace. This checks the explicit globs, not live Copilot routing. - Runtime builds/browser tests were not run for these Markdown-only changes. One baseline historical reviewer ran isolated MSBuild selection and synthetic alignment probes using a newer host SDK; those are not full historical-toolchain validation. > [!NOTE] > This PR description was generated with the assistance of GitHub Copilot. --------- Co-authored-by: Copilot App <[email protected]>
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.
Stacked on #136771 (opt-in
WasmRunWasmOptfor the CoreCLR native relink). Review only the two commits below; the base commit belongs to #136771.When
WasmRunWasmOpt=true, run wasm-opt over the per-app browser CoreCLR ReadyToRun images after crossgen2 and before webcil staging and fingerprinting. The option stays opt-in: per #136075, wasm-opt shouldn't be on by default while codegen is changing.Commits
94c0c69 — Support WasmRunWasmOpt for ReadyToRun images
BrowserWasmApp.CoreCLR.targets, where the Emscripten SDK provides wasm-opt._WasmCoreClrConfigureR2RWasmOptbuilds the wasm-opt arguments._WasmCoreClrOptimizeR2RImages(AfterTargets_CreateR2RImages) rewrites the images inobj/R2Rin place: each per-assembly image, or just the composite. Component stubs are skipped.*.wasm-opt.stampfile:WasmRunWasmOptandPublishReadyToRunare set but the workload targets aren't imported.@(_WasmOptFeatureFlag)(thenative.wasm.targetsbaseline plus relaxed SIMD); crossgen2's images carry notarget_featuressection either. Sign-ext and mutable-globals are binaryen defaults, so they aren't passed.--skip-pass=memory-packingkeeps the data segments intact. Passive segment 0 holds the payload and table sizes thatAttachWebcilSizesreads for the boot config.-O2; the relink in [browser][coreclr] Support WasmRunWasmOpt in the native relink #136771 defaults to-Oz. On R2R images-O2produced smaller Brotli output than both-Ozand-O3. An-Olevel inWasmOptConfigurationFlagsoverrides it.d643105 — Keep R2R Webcil payload aligned after wasm-opt
R2RDump --scfailed with aNativeCuckooFilterBadImageFormatException(Make wasm composite ReadyToRun images inspectable with R2RDump #132650).WebcilWasmPayloadAlignmentinMicrosoft.NET.WebAssembly.Webcil, plus anAlignWebcilPayloadtask that runs after wasm-opt. It re-pads segment 0 (at most 15 bytes per image) and keeps every segment's contents.-gis now always passed, so crossgen2's wasm debug-info settings ([browser][coreclr] Integrate R2R debug info flags into WebAssembly SDK #135754 / [browser][coreclr] Set WebAssembly ReadyToRun debug flags #136506) decide whether names exist.b487e93 — Address review: shared wasm-opt resolution, workload requirement, lane tests
_CoreCLRResolveWasmOpt($(_WasmOptPath)) instead of a second lookup.WasmRunWasmOpt=truefor CoreCLR (_WasmNativeWorkloadNeeded). Mono is unchanged. The SDK pack warning stays as a fallback for builds that still lack the workload targets, for example withUsingBrowserRuntimeWorkload=false.wasm-optlane, following its pattern of conditional asserts:AssertReadyToRunWasmOptchecks stamps and payload alignment when the lane enablesWasmRunWasmOpt, and that nothing was optimized otherwise.NativeLibraryTests.ProjectWithNativeReference_ReadyToRun, now taggedwasm-opt.PublishRunAllPagesWasmOptis replaced byReadyToRunTests.PublishRunAllPagesCompositeWithWorkload. No existing workload-mode test publishes a composite; the other R2R publish tests areno-workload, which the lane excludes.PInvokeTableGeneratorTests.UnusedQCallsAreTrimmedis taggedwasm-optbut doesn't setPublishReadyToRun, so it doesn't crossgen.Size (BlazorBasicTestApp, trimmed Release, Brotli bytes, wasm-opt off → on)
--wasm-debug-info none, as in #136506)Raw sizes: CoreLib 7.79 MB → 6.69 MB; the composite 13.7 MB → 10.0 MB with names stripped. wasm-opt adds roughly 0–4 s per publish here, within run-to-run noise.
Validation
./build.sh -os browser -s clr+libs+packs -c Release /p:InstallWorkloadForTesting=false /p:BuildCrossgen2HostPackForWorkloadTesting=true: succeeded../dotnet.sh build src/tasks/WasmAppBuilder/WasmAppBuilder.csproj -c Release: succeeded, no warnings../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=true -p:InstallWorkloadForTesting=false -p:XUnitMethodName=Wasm.Build.Tests.ReadyToRunTests.PublishRunAllPagesWasmOpt: passed 2/2../dotnet.sh build src/mono/wasm/Wasm.Build.Tests/Wasm.Build.Tests.csproj -c Release -t:Test -nodeReuse:false -p:TargetOS=browser -p:TargetArchitecture=wasm -p:RuntimeFlavor=CoreCLR -p:TestUsingWorkloads=true -p:InstallWorkloadForTesting=false -p:WasmRunWasmOpt=true) selected 16 tests and 15 passed.ProjectWithNativeReference_ReadyToRunoptimized 16 per-assembly images;PublishRunAllPagesCompositeWithWorkloadoptimized the composite and loggedLoaded R2rSuffixLibrary.r2r. The failure is the same environmentalWasmSIMDTests.PublishRelaxedSimdCoreClr(relaxedSimd: False)described below.WasmRunWasmOpt), where the helper asserts nothing was optimized.WasmRunWasmOpt=truegives_WasmNativeWorkloadNeeded=trueandUsingBrowserRuntimeWorkload=true. Without it, or withUseMonoRuntime=true, both stay off../dotnet.sh build src/mono/wasm/Wasm.Build.Tests/Wasm.Build.Tests.csproj -c Release -t:Test -nodeReuse:false -p:TargetOS=browser -p:TargetArchitecture=wasm -p:RuntimeFlavor=CoreCLR -p:TestUsingWorkloads=true -p:InstallWorkloadForTesting=false -p:WasmRunWasmOpt=true. It selected 16 tests and 15 passed, including bothPublishRunAllPagesWasmOptcases; their R2R arguments were--enable-exception-handling --enable-reference-types --enable-multivalue --enable-simd --enable-bulk-memory --enable-nontrapping-float-to-int --skip-pass=memory-packing -g -O2. The failure,WasmSIMDTests.PublishRelaxedSimdCoreClr(relaxedSimd: False), fails the same way outside the lane: locally it expects a12.0.0-devruntime pack underdotnet-latest/packs, which isn't installed.Loaded R2rSuffixLibrary.r2r: 42.BrowserWasmApp.CoreCLR.targets,native.wasm.targetsandWasmAppBuildertask assemblies were copied over the installed pack for these runs and restored afterwards.wasm-tools validate.R2RDump --sc --headerpasses on every per-assembly image and on the composite.WasmRunWasmOpttrue → true → false → false → true: optimizes, doesn't rerun, recompiles unoptimized, doesn't rerun, optimizes again.WasmRunWasmOpt=true, the new warning fires.Open risks
AttachWebcilSizesor the alignment task fails loudly rather than silently.obj/R2R. In workload mode the outer publish and the nested relink publish both run crossgen2 there (35 and 39 images in this app), so wasm-opt also runs twice. Related: [Browser][CoreCLR] publish+workload should not trigger native relink unless there is new UCO/PInvoke #132777, and the stale-copy note in [wasm][coreclr] ReadyToRun for CoreCLR browser-wasm #133378. Separately, an incremental workload-mode publish leaves duplicate fingerprinted copies even with wasm-opt off, which is why the new test doesn't reusePublishRunAllPagesCore.-gthis now follows crossgen2's settings.-O2in [browser][R2R] use wasm-opt to optimize size of webCIL #134439.Fixes #134439
Note
This PR description was generated with GitHub Copilot.