Skip to content

[wasm] Add V8 native code diffs alongside SuperPMI - #138595

Draft
pavelsavara wants to merge 3 commits into
mainfrom
pavelsavara/browser-wasm-superpmi-native-diffs
Draft

pavelsavara wants to merge 3 commits into
mainfrom
pavelsavara/browser-wasm-superpmi-native-diffs

Conversation

@pavelsavara

@pavelsavara pavelsavara commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Add an experimental superpmi.py wasm-native-diffs command that compares the same Browser ReadyToRun method as Wasm and as x64 code emitted by V8 Liftoff and TurboFan. The command can reuse saved publish snapshots and reports missing or ambiguous captures explicitly.
  • Add an opt-in Windows x64 Helix work item to SuperPMI asm diffs. The build agent prepares matching publishes and checksum-pinned V8 and Binaryen tools for a dedicated payload. The worker produces an independent artifact and a section in the existing summary.
  • Normalize recognized V8 helper address loads using the loaded-library map, preserving unmapped immediates and changes to call targets.

The pilot is off by default. It complements .mch replay and measures code size, not app throughput or startup.

How to try it

On Windows x64, run from the runtime checkout with Python, a compatible .NET 12 SDK, and the Browser runtime, WebAssembly SDK, and Crossgen2 packs at the same version. The WebAssembly SDK pack must already be in the NuGet cache because the fixture imports its targets during project evaluation. Set NUGET_PACKAGES if the packs are in a non-default cache. Set $dotnet, $d8, and $wasmDis to the paths of dotnet.exe, a disassembler-enabled d8 executable (V8 debug 16.0.141 was tested), and wasm-dis.exe (Binaryen 129 was tested). For jsvu, point to the installed .exe, not its .cmd shim.

Reproduce a known diff. Set $jit to clrjit_universal_wasm_x64.dll from the matching Crossgen2 pack. Use the same binary on both sides and disable inlining only for the candidate:

$packVersion = '12.0.0-alpha.1.26557.102'
python .\src\coreclr\scripts\superpmi.py wasm-native-diffs `
  -dotnet_path $dotnet -runtime_pack_version $packVersion `
  -v8_path $d8 -wasm_dis_path $wasmDis `
  -base_jit_path $jit -diff_jit_path $jit -diff_jit_option JitNoInline=1

For a real JIT comparison, pass the baseline and candidate binaries separately and omit -diff_jit_option. Both JITs must match the selected Crossgen2's JIT–EE interface. The tool uses a fixed Program.Target(int) console fixture, not an arbitrary app or .mch collection.

Read and rerun. The command prints its output directory (artifacts\spmi by default, overridable with -spmi_location or SUPERPMI_CACHE_DIRECTORY). Open summary.md for byte counts and links to the Wasm and native disassembly. result.json has the machine-readable result; commands.json records exact invocations. To skip publishing on a rerun, set $snapshot to the printed output directory:

python .\src\coreclr\scripts\superpmi.py wasm-native-diffs `
  -v8_path $d8 -wasm_dis_path $wasmDis `
  -base_publish "$snapshot\base" -diff_publish "$snapshot\diff"

Pass the same snapshot to both flags for an A/A check.

CI pilot. When the SuperPMI diffs pipeline is available, set spmi_wasm_native_diff_pack_version to the exact pack version compatible with both checked Wasm JITs. Leaving it blank keeps the pilot off. Look for the Browser/Wasm → V8 x64 summary section and WasmNativeDiffs.zip in the SuperPMI diffs artifact.

Validation

  • python -m unittest discover -s .\src\coreclr\scripts -p test_superpmi_wasm_native_diffs.py -v passed all six tests. SuperPMI Python scripts compiled, and git diff --check passed.
  • dotnet msbuild .\src\coreclr\scripts\superpmi-diffs.proj -getItem:HelixWorkItem with TargetOS=windows, TargetArchitecture=x64, and SuperPmiWasmNativeDiffs toggled showed the dedicated work item only when enabled.
  • The local preparation, worker, and summary ran using two distinct checked Wasm JITs (50a63f58444 and 71cbb0b2549) with matching 12.0.0-alpha.1.26575.102 packs. Crossgen2 used the intended JIT on each side. All three stages matched for the fixture.
  • The JitNoInline=1 positive control still reported changes in all three stages after normalization: +22 Wasm bytes, +532 Liftoff x64 instruction bytes, and +480 TurboFan x64 instruction bytes.
  • Live Azure DevOps/Helix execution was not run. The public SuperPMI diffs definition is disabled and rejected a preview-only request.

Note

This description was generated with GitHub Copilot.

pavelsavara and others added 2 commits December 1, 2026 15:00
Compare the same ReadyToRun method through Crossgen2, V8 Liftoff, and V8 TurboFan, with reproducible publish snapshots and linked disassembly.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Stage matching ReadyToRun publishes and pinned V8 tools for an opt-in Windows x64 Helix work item. Report the comparison alongside existing SuperPMI diffs and normalize mapped V8 helper addresses without hiding changed call targets.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Dec 1, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@pavelsavara

Copy link
Copy Markdown
Member Author

Example: native code diffs from the fixed Browser ReadyToRun fixture

This is from a local run with Windows x64 V8 debug 16.0.141. Both publishes used the same Wasm JIT binary; the candidate added -diff_jit_option JitNoInline=1 as a positive control. Both runs still returned 42.

Program.Target(int) — 1/1 matched per stage

Stage Changed bodies Base bytes Diff bytes Delta
Wasm 1 21 43 +22
Liftoff x64 1 212 744 +532
TurboFan x64 1 324 804 +480

Selected lines from the generated Wasm patch (not the full hunk):

-  (i32.shl
+  (call_indirect (type $0)

Selected lines from the generated TurboFan x64 patch (offset, instruction bytes, disassembly):

-   b7  8d0412                   leal rax,[rdx+rdx*1]
+  23e  43ff140a                 call [r10+r9*1]

The local report links to full baseline/candidate disassemblies and patches for all three stages. These are emitted byte counts, not performance measurements.

Note

This comment was generated with GitHub Copilot from verified local output.

@pavelsavara pavelsavara added arch-wasm WebAssembly architecture os-browser Browser variant of arch-wasm labels Dec 1, 2026
@pavelsavara pavelsavara added this to the 12.0.0 milestone Dec 1, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.

from superpmi_wasm_native_diffs import REPO, SCRIPTS, sha256, write_json


JIT = "clrjit_universal_wasm_x64.dll"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I will move the installation elsewhere

Acquire pinned V8 debug and shared Binaryen through the Wasm tool cache. Restore the cache in opt-in CI jobs while continuing to stage tools for offline Helix execution.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI os-browser Browser variant of arch-wasm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant