Repository navigation
[Wasm] Emit cold method bodies to an auxiliary module - #138163
jtschuster wants to merge 20 commits into
Conversation
Remove the temporary runtime-generated metadata fallback now that crossgen2 emits the AuxiliaryModuleMetadata section. Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
- Sort Wasm thunks ahead of compiled methods via CustomSort instead of partitioning in the WebCIL object writer, and assert the invariant. - Emit the sidecar Function and Code sections with WasmExternallyCountedSection; rename primary section fields and store auxiliary code as a slice. - Update tests to account for the first compiled method's table slot. Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
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. |
|
Tagging subscribers to this area: @dotnet/crossgen-contrib |
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
|
@jtschuster I found #138199 problem during my experiments and created jtschuster#108 on top of this PR for it. You can take what makes sense to you and/or close it. |
HavitApp size and startup measurementsI built crossgen2 and the browser-wasm packs from this PR at Profile: Variants:
Composite R2R module sizes
Most of the growth is code (+2.37 MB):
The primary module's data section also grew by about 140 KB. Startup measurementsThe PR doesn't load the aux module at runtime yet, so I added a local prototype (not part of this PR) to do it:
Measured with the macro-benchmarks harness on Playwright Chromium: 10 cold and 5 warm loads per profile. All times are in ms. "TTM" (time to managed code) runs from page script start until the first
Why TTM is slower: startup code lands in the aux moduleI enabled
Methods are placed in the aux module when they aren't in the profile, and the generic Blazor profile doesn't cover Havit's startup path. Of the extra interpreted methods:
Many are framework startup code: the Ideas for fixing this (not tested):
Caveats
Note This comment was generated with GitHub Copilot from locally collected measurements. |
Co-authored-by: Copilot <[email protected]> Copilot-Session: c60f0ec2-58cf-479f-9e53-fa5a466cfbe8 # Conflicts: # src/coreclr/tools/Common/Compiler/ObjectWriter/WebCilObjectWriter.cs
Adds crossgen2 support for emitting cold method bodies to an auxiliary module. The set of methods are determined by a .mibc file along with some heuristics. If no profile is provided, all methods go into the primary module. All methods in the .mibc are placed in the primary module when a .mibc file is provided no matter the call count for each.
NodeFactory.IsAuxiliaryCandidate()also uses some heuristics to make sure some methods are always in the primary module.Methods are sorted before passing to the ObjectWriter such that all auxiliary methods come after all primary module methods. The object writer can then split the WasmCode section at the first method symbol where
IsAuxiliary == true. Thunks are sorted ahead ofMethodWithGCInfoand placed in the primary unconditionally to accomodate this as well. OnlyMethodWithGCInfonodes can be placed in the auxiliary module.Non-default method sorting is not supported with auxiliary methods in this PR. I think we can support it later if necessary.
ActivateModule()is exported from the auxiliary module. It copies the table element at__table_base + <primaryTableSlotCount>. The module contains no data segments.Perfmap and symbol info for auxiliary modules are emitted into separate files following the same naming pattern as the wasm aux module (
<PrimaryModuleName>.1.wasm/<PrimaryModuleName>.1.symbols).Todo in followups: