Repository navigation
Open
Labels
arch-wasmWebAssembly architecturearea-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone
Description
This is a potential code size issue; The method in question where this came up is System.Collections.Hashtable.Contains(object); The x64 codegen looks like:
564330: 4c 8d 1d 89 79 b0 00 lea r11, [0x106bcc0] // bool System.Collections.Hashtable.ContainsKey(object) (VIRTUAL_ENTRY)
564337: 39 09 cmp dword ptr [rcx], ecx
564339: 49 ff 23 jmp qword ptr [r11]Whereas the wasm codegen is substantially larger, and contains a GDV expansion:
; WASM table index: 22773, function index: 18151
; Parameters:
; [0] i32
; [1] i32
; [2] i32
; [3] i32
; Locals:
; [4] i32
; [5] i32
; [6] i32
; [7] i32
; Results: i32
0000: local.get 0
0002: i32.const 16
0004: i32.sub
0005: local.tee 0 // establish sp for new frame
0007: local.get 3
0009: i32.store align=1 // store PEP
000C: local.get 0
000E: local.get 1
0010: i32.store align=1 offset=12 ; spill `this` arg (this should now be elided)
0013: local.get 0
0015: local.get 2
0017: i32.store align=1 offset=8 ; spill `object` arg (this should now be elided)
001A: block
001C: block
001E: block
0020: local.get 0
0022: i32.const 1
0024: i32.store align=1 offset=4 // VIP update
0027: global.get 1 // imageBase
0029: i32.load align=1 offset=6555736 // System.Collections.Hashtable (TYPE_HANDLE)
002F: local.get 0
0031: i32.load align=1 offset=12 // load `this` arg
0034: local.tee 7
0036: local.get 7
0038: i32.eqz // null check `this`
0039: br_if 2
003B: i32.load align=1 // load method table from `this`
003E: i32.ne // compare to `System.Collections.Hashtable` method table for fast path
003F: br_if 0
// GDV fastpath for exact match System.Collections.Hashtable
0041: local.get 0
0043: local.get 0
0045: i32.load align=1 offset=12
0048: local.get 0
004A: i32.load align=1 offset=8
004D: global.get 1 // imageBase
004F: i32.load align=1 offset=6522148 // bool System.Collections.Hashtable.ContainsKey(object) (METHOD_ENTRY_DEF_TOKEN)
0055: local.tee 4
0057: local.get 4
0059: i32.load align=1
005C: call_indirect 0 (type 152)
0060: local.set 5
0062: br 1
0064: end
// virtual fallback
0065: local.get 0
0067: local.get 0
0069: i32.load align=1 offset=12
006C: local.get 0
006E: i32.load align=1 offset=8
0071: global.get 1 // imageBase
0073: i32.load align=1 offset=6472628 // bool System.Collections.Hashtable.ContainsKey(object) (VIRTUAL_ENTRY)
0079: local.tee 6
007B: local.get 6
007D: i32.load align=1
0080: call_indirect 0 (type 152)
0084: local.set 5
0086: end
0087: local.get 5
0089: return
008A: end
008B: local.get 0
008D: i32.const 1
008F: i32.store align=1 offset=4
0092: local.get 0
0094: i32.const 0
0096: call 19847
009A: unreachable
009B: endThe reason for the expansion on the Wasm side seems to be the lack of implicit tail calls; The virtual call to System.Collections.Hashtable.ContainsKey(object) can be an implicit tail call on x64 and so it is excluded as a gdv candidate:
runtime/src/coreclr/jit/importercalls.cpp
Line 9288 in a76b3ff
| if (call->CanTailCall()) |
However, we've disabled implicit tail calls on Wasm and so we instead keep the gdv. This is a fairly size-expensive expansion, and though it might improve perf we might consider whether allowing a tail call here would be better to reduce size.
Metadata
Metadata
Assignees
Labels
arch-wasmWebAssembly architecturearea-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Activity
[-][wasm] Lack of Implicit Tail Calls Leads to GDV Expansion[/-][+][wasm] CQ: Lack of Implicit Tail Calls Leads to Size-Expensive GDV Expansion[/+]dotnet-policy-service commentedon Oct 21, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
dotnet-policy-service commentedon Oct 21, 2026
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.
jakobbotsch commentedon Oct 30, 2026
I think we should separate more clearly what a tailcall in wasm entails, because I do not think it makes sense to emit
return_callon wasm. As @SingleAccretion has said previously, this is purely a constraint on the WASM code generator. We would not want IL generators to opportunistically emittail.prefixes either.If tailcalls allow us to simplify prolog/epilog generation then that sounds worthwhile, but it does not necessarily require emission of
return_call.The other consideration is that it sounds like we may want a different heuristic for perf vs size trade offs when it comes to GDV.
adamperlin commentedon Oct 30, 2026
That definitely makes sense. It sounds like a very good idea to separate what a tail call on Wasm entails and what we would hope to gain by emitting them in our code generator and perhaps this could be a separate issue.
I agree that we may want a different heuristic for GDV when it comes to size vs. perf and I do think this is worthwhile to investigate for Wasm. cc @AndyAyersMS
AndyAyersMS commentedon Nov 12, 2026
Are we seeing GDVs in current apps like Blazor Havig? I do not see us using a MIBC, though it seems like eventually we should.
adamperlin commentedon Nov 13, 2026
This example came from a wasm build of System.Private.CoreLib from the default browser runtime build. I'm not sure whether we use a MIBC file there? I haven't looked into this issue on Havit at all, but perhaps we should?