Repository navigation
Wasm: omit frame header for optimized methods that make no calls - #137770
Merged
Merged
Conversation
When optimizing a method with no EH, scan the LIR for calls and stores that may emit helper calls. Conservatively exclude localloc as well, even though its Wasm codegen does not emit a call. When neither is present, omit the virtual IP and function index frame header. This removes the dead SP adjustment in leaf methods like Int32.IsPow2 while retaining space for stack locals. Add an assert in ensureCurrentFuncIsUnwindable to catch call sources the scan misses. Co-authored-by: Copilot <[email protected]> Copilot-Session: bfdc6001-97e4-4f7a-9de1-f9a04223c8ff
|
Azure Pipelines: Successfully started running 6 pipeline(s). 9 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 this area: @JulieLeeMSFT, @jakobbotsch |
AndyAyersMS
requested review from
adamperlin
and
a balanced review from Copilot
November 17, 2026 20:04
Member
Author
|
@adamperlin PTAL Another uncompressed smaller / compressed larger change, but the smaller Wasm should be beneficial at runtime too. |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The review reports no active issues with the Wasm frame-header optimization.
No open issues 🎉
What changed in this PR
This PR reduces unnecessary Wasm frame setup in the JIT by omitting the shadow-stack frame header for optimized, non-NativeAOT methods without exception handling when code generation cannot emit calls.
Changes:
- Adds a conservative LIR scan for explicit calls and operations that may emit helper calls.
- Uses the scan to omit unused frame headers while preserving stack-local space and existing minopts behavior.
- Adds an assertion to catch call-emitting paths that lack a frame header.
| File | Description |
|---|---|
src/coreclr/jit/fgwasm.cpp |
Detects potential calls and conditionally omits the frame header. |
src/coreclr/jit/compiler.h |
Declares the new call-detection helper. |
src/coreclr/jit/codegenwasm.cpp |
Asserts that unwindable main methods have a frame header. |
Review effort: Balanced
adamperlin
approved these changes
Nov 17, 2026
Member
Author
|
/ba-g osx libraries job stopped responding mid build |
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.
When optimizing a Wasm method with no EH, omit the shadow-stack frame header (virtual IP and function index slots) if codegen cannot emit a call.
Today the no-EH path in
fgWasmVirtualIPallocates the frame header whenever the method has any nonempty block. For leaf methods such asInt32.IsPow2that header is never written or read, but it still forces a dead SP adjustment in the prolog (local.get; i32.const 16; i32.sub; local.set) and a nonzero unwind frame size. A leaf method can never be on the shadow stack during a stack walk: GC, exceptions and unwinding only happen at calls, and null/bounds/divide checks branch to throw-helper blocks, which contain calls.fgWasmMayEmitCallscans the LIR for anything codegen may turn into a call:GT_CALL, which includes throw-helper block calls (materialized byStackLevelSetterbefore this phase)GT_STOREINDneeding a write barrier (same predicate codegen uses)GT_STORE_BLKother than the native-opcode and loop forms (the CpObj path callsCHECKED_ASSIGN_REF)GT_LCLHEAP, excluded conservatively (Wasm localloc codegen does not call)The scan only runs when optimizing, so minopts throughput is unaffected. Stack locals still get frame space; only the header goes away. An assert in
ensureCurrentFuncIsUnwindablecatches any call source the scan misses.Measurements
SuperPMI, Wasm cross-JIT (
-target_os browser -target_arch wasm), Checked asmdiffs; no asserts:Release tpdiff: -0.00% (coreclr_tests), +0.02% (libraries).
Blazor Havit composite R2R (same inputs and Crossgen2; only the JIT differs): code section -7,402 bytes (1,057 methods, 7 bytes each); file -7,392 bytes. Compressed sizes go up slightly (Brotli +5,455, GZip +3,236); likely because the removed sequences were identical across methods and compressed well. Browser startup and walkthrough latency on Havit showed no measurable change, and V8's Wasm inlining decisions were essentially unchanged.
Contributes to #135985 (Prolog/Epilog: drop frame setup for methods that don't need unwinding).
Note
This PR description was drafted with GitHub Copilot.