Repository navigation
[browser][CoreCLR] Collect ReadyToRun PGO with indexed schemas - #137502
pavelsavara wants to merge 15 commits into
Conversation
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
|
Tagging @dotnet/jit-contrib for JIT-EE GUID update |
|
Tagging subscribers to this area: @dotnet/crossgen-contrib |
|
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. |
|
@pavelsavara, why do we only capture data subset of methods. I would expect it would be simpler to capture all the data and then filter in dotnet-pgo. Also, why do we do block counts instead of edge counts like other jitted platforms? They should be basically equivalent. I would hope to have instrumentation which is as similar as possible to our normal platforms. |
|
I had more or less similar feedback. I am not sure why we need extra something beyond making our "normal" PGO work for R2R images.
|
Cover a shared target instantiated over an external reference type (the constraint is omitted), and an unshared value-type instantiation and generic method dictionary over external types (the exact instantiation is kept). Also check that the shared body's exact instantiation is still supplied by its TypeDictionary import. Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
The existing test supplies CoreLib only as a reference, so deferred Wasm direct calls are disabled and its MethodEntry_ReadyToRun readiness fixups are never emitted. Add a Wasm composite variant with CoreLib as an unrooted input that requires a constraint-free MethodEntry_ReadyToRun import for Enumerator`1.Dispose and an ordinary MethodEntry import for the NoInlining control. Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
|
Quick update to the Dynamic PGO comparison as of
After merging Note This update was prepared with GitHub Copilot. |
Browser ReadyToRun PGO vs. historical InterpPGOI ran BlazorWasm and Havit Bootstrap locally in headless Chrome 158 on Windows, using the Debug Browser CoreCLR runtime from this PR at The MIBCs combine measured R2R counters with metadata-backed interpreter rundown roots. Havit Bootstrap: corrected platform-filtered MIBC (ZIP) The Havit profile was regenerated from the same trace using the full SDK assembly allowlist plus the two browser-specific Blazor references. The previous merge used abbreviated names from the text dump and unintentionally dropped
Converting each trace with and without Note This comparison was prepared with GitHub Copilot. |
In a composite image containing CoreLib, deferred Wasm readiness imports for Queue<Marker>.Enumerator.Dispose and KeyValuePair<Marker, int>.ToString must name only the shared CoreLib body, not the app-type constrained owner. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Deferred Wasm call finalization can legitimately leave KeyValuePair.ToString as an ordinary MethodEntry in the composite. Keep the strict MethodEntry_ReadyToRun requirement for Queue.Enumerator.Dispose, while requiring the KeyValuePair import to be constraint-free regardless of the finalization choice. Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
|
Wanted to see if JIT changes lead to any diffs in native targets, but SPMI job didn't run. Not sure why... |
Resolved constrained calls whose target is an async variant (awaited call in a runtime-async method) or an instantiating stub (constrained. ldftn on a generic value type) previously fell back to encoding the constraint. Name the async variant by its primary method's token, and allow instantiating stubs: their target is exact, so the signature still encodes the exact owning type. Add an R2R unit test for the async case and runtime tests in src/tests/readytorun covering the existing cases, the async case, and an IL constrained. ldftn test. Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Ran the tests on browser WASM R2R locally. ResolvedConstrainedCall passes as is. ResolvedConstrainedAsyncCall passes once DisposeAsync completes synchronously, since browser cannot block on a pending task. ConstrainedLdftn still fails because typeof(T) reaches an interpreted CoreLib helper through an R2R-to-interpreter thunk crossgen2 does not register, so keep it excluded with an accurate comment. Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Add PublishReadyToRunPgoInstrumentation to the Browser CoreCLR ReadyToRun targets. It passes --pgo-instrumentation on publish, and publish fails if threads are enabled or diagnostics are disabled. Move the Browser EventPipe diagnostics scenarios into a reusable test asset and add end-to-end producer and consumer tests: train in the browser, collect a trace, create a .mibc with dotnet-pgo, and verify that the consumer publish uses the measured counts and type profiles. Document the workflow in features.md. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
65dacc2 to
09bbaf8
Compare
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
| #### CoreCLR profile-guided ReadyToRun publishing | ||
|
|
||
| Set `PublishReadyToRunPgoInstrumentation=true` to instrument compiled CoreCLR ReadyToRun | ||
| methods, including inlined bodies. This setting is |
Summary
This PR adds opt-in PGO collection for published Browser/CoreCLR ReadyToRun apps. You train the app in a browser, collect a trace, convert it to MIBC with
dotnet-pgo, and pass the profile to the next ReadyToRun publish.Instrumented ReadyToRun code collects the same data as JIT instrumentation elsewhere:
MemmoveandSequenceEqualOn republish, crossgen2 uses this data the usual way: flow reconstruction, value specialization, and guarded devirtualization or delegate inlining.
To use it:
PublishReadyToRunPgoInstrumentation=true.collectPgoTrace().dotnet-pgo create-mibcagainst the matching IL.PublishReadyToRunPgoFilesand instrumentation turned off.The full workflow is documented in
src/mono/wasm/features.md.Stack
This change is split into a stack of PRs. Review each layer separately, bottom first. This PR is the integration layer on top.
PgoManagerhardeningdotnet-pgoallocation mergingThe lettered areas below describe the whole stack.
Areas of change
A) Feature gating.
clrfeatures.cmakedefinesFEATURE_R2R_PGOonly for single-threaded Browser/Wasm withFEATURE_PGO. The standalone Wasm JIT always defines it (jit/CMakeLists.txt), because crossgen2 hosts that JIT on desktop. Everything below depends on this switch.B) R2R image format.
readytorun.hbumps R2R to 34.2 and adds:PgoInstrumentationSchemas(129);PgoInstrumentationData(0x3C): a method signature followed by a schema index;ValueProfile64,ClassProfile64andDelegateProfile64(0x11A–0x11C).The managed copies (
ModuleHeaders.cs,ReadyToRunConstants.cs, NativeAOTModuleHeaders.h) and the R2RDump signature parser are updated to match. The image stores no counters, only deduplicated schemas.C) JIT counter addressing. In
fgprofile.cpp, the newGetProfileAddressmakes R2R probes load the counter base from an import cell (an invariant load) plus an offset, instead of a constant slab address. R2R instrumentation forces 64-bit counters and one slot per counter, with no interlocked or scalable updates. The scatteredJitConfigreads move into newopts.compPgo*fields. Writing synthesized counts is disabled for R2R, because the profile address is only a symbol at compile time.D) JIT probe kinds enabled for AOT.
fgPrepareToInstrumentMethodandcompClassifyGDVProbeTypenow turn on edge, class (type), value and delegate histograms, plus cast probes (fgR2RCastProfiling), when R2R PGO is active. Before this, they were JIT-only. VTable method profiling stays off.E) JIT guarded devirtualization for Wasm R2R interface calls. A new flag,
GTF_CALL_M_R2R_INTERFACE_LDVIRTFTN, marks non-generic interface calls that Wasm R2R imports through ldvirtftn. Those calls can then get class probes and guarded devirtualization. Inindirectcalltransformer.cpp,SplitCallgains afallbackUseparameter so the ldvirtftn control expression runs only on the fallback path.F) JIT delegate guarded devirtualization in R2R.
pickGDVallows method profiles for delegate calls on Wasm R2R.impTransformDevirtualizedCallusesgetFunctionFixedEntryPointfor the guarded delegate target. Crossgen2 implements that call for Wasm only, restricted byCanReferenceDelegateProfileTarget.G) Crossgen2 schema table and fixup nodes. The new
PgoInstrumentationSchemaTableNodekeys entries by content, sorts them so the output is deterministic, and ownsLayout, the counter-offset layout the runtime re-derives identically. The newPgoInstrumentationDataSignatureencodes the fixup. The node factory registers the section.H) Crossgen2 JIT-EE interface glue. In
CorInfoImpl.ReadyToRun.cs,allocPgoInstrumentationBySchemahands the JIT a pinned pointer-sized cell and attaches the import as a precode fixup.recordRelocation/findKnownBBCountBlockmap that cell back to the import. Other pieces:_pgoTokenMissing).getJitFlagssetsCORJIT_FLAG_PGO_INSTR.I) Crossgen2 command line. The new
--pgo-instrumentationoption is rejected unless the target is single-threaded browser-wasm. Instrumented builds keep their original IL even when--strip-il-bodiesis requested.J) Runtime fixup resolution. In
jitinterface.cpp,LoadDynamicInfoEntrydecodes the method and schema index. It then calls the newPgoManager::allocPgoInstrumentationFromR2RSchema, which validates the section (offset table, record kinds and flags, histogram pairing, IL offset bounds, no duplicates) before allocating. Runtimes withoutFEATURE_R2R_PGOreject the fixup, so the method falls back to non-R2R execution.K)
PgoManagerunderFEATURE_R2R_PGO. Inpgo.cpp:nextForMethod. An existing allocation is reused only if its schema matches exactly.GetStableHashmoves before the lock, and overflow checks are added.Counters are exported through the existing
JitInstrumentationDataEventPipe events when the PGO session stops.L)
dotnet-pgo.create-mibcnow merges (sums) several completed allocations for one method, for example inlined copies in several ReadyToRun bodies, instead of dropping the method. It ignores allocations that never executed and strips empty handle-histogram slots. If a method has both block and edge counts (interpreterDOTNET_InterpPGOplus ReadyToRun), it warns and skips that method's counters. Instrumentation-data events alone can now put a method into the profile.M) SDK targets.
PublishReadyToRunPgoInstrumentation=trueadds--pgo-instrumentationon publish only; a plain build ignores it. The publish fails ifEnableDiagnosticsisn't true orWasmEnableThreadsis true. The flag is part of the R2R up-to-date state, so toggling it reruns crossgen2.N) Tests.
WasmArgumentLayoutTests: schema deduplication and layout, inlinee probes, IL preservation, and receiver, delegate and cast probes.EventPipeDiagnosticsTests: train in the browser → MIBC → republish → assert codegen. The existing Browser diagnostics scenarios move into theDiagnosticsScenariostest asset so the producer and consumer publishes can be shared.ReadyToRunTests.dotnet-pgomerge unit test.O) Docs.
src/mono/wasm/features.mddocuments the producer →dotnet-pgo→ consumer workflow. Thedotnet-pgoREADME describes how allocations are merged.P) Merged-in #138262.
ComputeCallTargetMethodWithToken, theMethodFixupSignatureasserts, theConstrainedCalls/*test cases, theR2RTestSuitestests andsrc/tests/readytorun/resolved-constrained-callscome from #138262 (Wasm R2R method-entry imports for resolved constrained calls, fixes #138199). It is a fork PR, so it can't join the stack. Its latest head is merged into this PR only, and those changes will drop out of this diff once it lands on main.Out of scope
JitVTableProfiling)This is offline training followed by a republish.
See the Dynamic PGO comparison and its delegate profiling follow-up.
Follow-ups
Tracking: #130521 (broader interpreter and exception-profile work remains open).
Note
This PR description was updated with GitHub Copilot assistance.