Skip to content

[browser][CoreCLR] Include interpreted methods in dotnet-pgo profiles - #138575

Draft
pavelsavara wants to merge 55 commits into
mainfrom
pavelsavara/browser-coreclr-r2r-pgo-interpreted-rundown
Draft

pavelsavara wants to merge 55 commits into
mainfrom
pavelsavara/browser-coreclr-r2r-pgo-interpreted-rundown

Conversation

@pavelsavara

Copy link
Copy Markdown
Member

Important

Stacked on #137502. Until that merges, only the last commit belongs to this PR.

On Browser, methods that are not precompiled by ReadyToRun run on the CoreCLR interpreter. The interpreter does not emit JIT instrumentation events. Unless DOTNET_InterpPGO instruments them, such methods are missing from a PGO trace, so a profile-guided republish cannot pick them up for precompilation.

This PR adds dotnet-pgo create-mibc --include-interpreted-rundown. The option selects interpreted methods that are backed by metadata from the trace's method-load and rundown events, and adds them to the .mibc as method-presence roots. It doesn't invent any counts. The next crossgen2 run then compiles those methods.

Changes

  • dotnet-pgo:
    • Adds the --include-interpreted-rundown option.
    • Adds a classifier for interpreted code ranges. A range qualifies only if the trace is 32-bit Wasm, the code range is non-empty and 32-bit, the method is Jitted but not dynamic or a JIT helper, and it has a valid MethodDef token.
    • Keeps all TraceLog events so these code ranges are retained.
  • CoreCLR EventPipe provider: enumerates capture state when the session stops (FEATURE_R2R_PGO), so method and type identities for interpreted code ranges are written before the provider stops.
  • Browser PGO collector: enables the EndEnumeration keyword (0x80).
  • Tests:
    • A dotnet-pgo unit test for the classifier.
    • WBT coverage: a method-presence-only InterpPgo case, and an interpreted-only FallbackLibrary method in the sparse-edge ReadyToRun round-trip. The test checks that the method is ReadyToRun-compiled after the profile is consumed.
  • Docs: dotnet-pgo README and src/mono/wasm/features.md.

Validation

All run locally on Windows, with the Browser CoreCLR Debug runtime pack built from this branch:

  • dotnet-pgo.Tests: 22/22 passed, including 14 cases for the interpreted-range classifier.
  • BlazorEventPipeTestWithInterpPgo: 3/3 passed. One case collects presence only, without DOTNET_InterpPGO.
  • BlazorEventPipeTestWithSparseEdgePgoReadyToRun: 2/2 passed (composite, and non-composite with CPU sampling). This includes the interpreted-only FallbackLibrary method being ReadyToRun-compiled after the profile is consumed.

Note

This PR description was generated with GitHub Copilot.

pavelsavara and others added 30 commits November 13, 2026 11:13
Collect 64-bit IL block profiles through normal JIT instrumentation and
preserve distinct intrinsic and interpreter invocation contributions.
Resolve indexed R2R schemas to stable counter storage and carry the
profiles through EventPipe, MIBC, and partial ReadyToRun consumption.

Add publish configuration, schema and compiler regressions, browser
round trips, and usage documentation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Preserve legacy interpreter profiling outside single-threaded Browser,
use per-method schema allocation chains, and handle sparse flow inference
conservatively when exception exits are not measurable.

Include the pending main merge and all local PGO fixes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Require exactly one method with counter data rather than one method in
the entire MIBC. Rundown-only method records are expected in published
application traces and do not indicate instrumentation filter leakage.
Preserve the exact invocation count, schema kind, and IL offset checks.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Preserve AuxiliaryModuleMetadata at section 128 and assign the PGO schema
section 129 in format 34.2. Generate a new combined JIT/EE interface GUID.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Integrate main cfe5c10 while preserving the R2R PGO changes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use the ordinary JIT sparse-edge producer and consumer with the indexed
R2R schema storage and counter-address imports. Remove custom invocation
records, expanded-intrinsic markers, and invocation/body scaling.

Preserve the existing optional interpreter profiling facility. Capture
method identities once before the runtime provider stops so dotnet-pgo
can discover prepared interpreter bodies without enabling their counters.

Update SDK wiring, documentation, and profile/publish/browser coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Merge c7cc512 without
changing the production PGO design or experiment branch.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Define the profiling capability on the Wasm JIT target rather than relying
on the outer CMake target OS. Linux-hosted cross-component builds otherwise
emit BasicBlockIntCount schemas that the R2R counter table rejects.

Keep the runtime's Browser and single-thread support boundaries unchanged.
Document the distinction between compiler capability and runtime support.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use shared effective settings for block and edge probes and honor minimal
prejit profiling. Read counter width on Wasm32 and inherit it in inlinees,
preserving the required 64-bit R2R layout.

Keep measured input when the compiler cannot write synthesized counts
through R2R imports. Cover the configuration paths in Wasm compiler tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Reuse the standard integer histogram probe for Memmove and SequenceEqual
lengths. Export filled samples alongside sparse edge counts so existing
EventPipe-to-MIBC tooling can carry both in the same profile.

Cover the value-probe toggle and verify exact samples in the Blazor
producer/consumer roundtrip.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Report an actionable Crossgen2 error instead of silently forcing
64-bit counters when Wasm R2R instrumentation is enabled and the
effective JitCollect64BitCounts override is zero.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Report explicit interlocked, scalable, or multi-slot padding requests
instead of silently using direct single-slot counters. Leave the
supported overrides and uninstrumented compilations unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Initialize the JIT's 64-bit count option on 32-bit non-Wasm targets,
treat whitespace-only Wasm PGO filters as disabled in Crossgen2 and the
SDK, and keep flush-time instrumentation roots from overriding time
windows already applied to observed R2R or JIT method events.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Crossgen2 already applies canonical profiles to exact generic inlinees, so
the extra lookup is unnecessary.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Log and skip incompatible counters for the affected method only. Capture method identities independently of counter export, and cover mixed ReadyToRun and interpreter profiling in Chrome.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Share address generation between JIT and R2R probes, and mark the resolved R2R import-cell pointer invariant. Inherit the root counter width for all inlinees.

Rename the internal R2R instrumentation filter without changing the Browser SDK property. Remove raw counter-option validation while keeping the supported R2R probe mode and retained-IL requirement.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Collect cast type histograms in Browser CoreCLR ReadyToRun and export them through the existing EventPipe and MIBC path. Treat unreferenceable types as unknown so speculative guards cannot prevent R2R compilation.

Wire PublishReadyToRunPgoInstrumentation to the Crossgen2 --pgo-instrumentation switch. Preserve all original IL in instrumented images without validating raw JIT options.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Drive instrumentation through CORJIT_FLAG_BBINSTR without rewriting JIT options. Preserve the composite-only IL stripping diagnostic before retaining IL in instrumented images.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
When crossgen2 resolves a constrained call at compile time to a method
body in the version bubble, encode the call target import with that
method's own token and no constrained type. The runtime cannot resolve
the call differently, and decoding the constraint eagerly loaded the
exact constrained type and its instantiation arguments (for example
Enumerator<Marker> for a foreach Dispose call), which could load
application assemblies during early startup on Wasm.

Fixes #138199

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Use receiver type histograms to enable guarded devirtualization on republish, preserving the original dispatch on the fallback path. Clear stale histogram flags when early block splitting leaves a block without a probe.

Addresses review feedback on #137502.

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

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
…calls

MethodDictionary and DeclaringTypeHandle instantiation-argument lookups for a
constrained call resolved at compile time now name the resolved method by its
own token, like the call's entrypoint import. Assert in MethodFixupSignature
that re-tokenized methods never carry a constraint.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

# Conflicts:
#	src/coreclr/jit/fgprofile.cpp
#	src/coreclr/jit/importercalls.cpp
Export delegate method histograms through the existing EventPipe and MIBC pipeline. Use portable entrypoints to guard and inline eligible closed instance targets while preserving the original invocation on misses.

Follow-up for #137502.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Validate the instrumentation property in the publish pipeline instead of checking a dotnet CLI marker from Build. Leave ordinary builds uninstrumented.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Cache successful validation on the loaded image shared by composite components. Keep fixup-time validation of the requested schema and its IL keys.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Validate encoded offsets before allocation and size the slab from the checked end of the last record in the monotonic layout.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
pavelsavara and others added 25 commits November 26, 2026 00:55
Ignore unused allocations when choosing between interpreter and R2R observations. Still report and skip the mixed method when both producers observed execution.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove feature-wide JIT defaults. R2R instrumentation already forces 64-bit counters with one direct update slot on each compilation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The schema reader takes its callback by value. Forward from a reference-capturing callback so serialization updates the writer used to emit the event.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use an actual static method and observe each multicast target independently, so the test cannot pass if the first target is skipped.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Make disposal observable without instrumentation so the deferred-call import regression can run with or without the PGO producer.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Drop the readiness-import cache keying on the canonical method body and
the DirectCallActivationUsesCanonicalBody test. #138262
fixes #138199 at the token source instead, which also
cleans ordinary lazy METHOD_ENTRY imports.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Take the token-source fix for #138199 in place of the
reverted canonical method-entry keying.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Resolve conflicts with the WASMARCH predicate rename (#138190) and the
removal of runtime categories from WBT (#138425): keep the R2R
interface LDVIRTFTN marking under TARGET_WASMARCH, and use plain
Theory/Fact without the coreclr category for the PGO WBT tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Drop the generic Browser validator. The property only acts when it is
'true' and ReadyToRun publishing runs, and crossgen2 already rejects
non-Browser/wasm32 targets. Keep the two checks nothing else enforces,
EnableDiagnostics and WasmEnableThreads, in the target that adds
--pgo-instrumentation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Drop compiler-level tests whose behavior is covered end to end by
BlazorEventPipeTestWithSparseEdgePgoReadyToRun (sparse edge, IL-offset-0
backedge, value probes and likelihood round trip), the config-knob rows
of InlineeProfilingPreservesInlining, and the non-composite rows of the
strip-IL test, which only exercised an existing crossgen2 error.

Run the sparse-edge Blazor test in Release only, keeping the composite
and CPU-sampling cases.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Label DelegateProfile64 imports as DELEGATE_PROFILE64 in R2RDump.
- Revert whitespace-only changes to jitconfigvalues.h.
- Condense the R2R PGO section of features.md to the user-facing
  workflow and drop the stale Mono note.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use the existing ByteArrayComparer for deduplication and a byte span
comparison for ordering instead of materializing hex and SHA256 strings.
The ordering is identical to the previous uppercase hex ordinal sort.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Each schema blob now contains only recordCount and kind/ILOffset/Count/Other
records. Counter offsets and the total counter size follow deterministically
from the records, and allocPgoInstrumentationBySchema already recomputes the
layout and rejects overflowing sizes, so the runtime reader no longer lays out
or cross-checks the schema itself.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Drop LayoutR2RPgoInstrumentationSchema and ReadLivePgoInstrumentationSchema
and use LayoutPgoInstrumentationSchema/ReadInstrumentationSchemaWithLayout
everywhere. The R2R variant only differed for zero-size NumRuns/Version
records, which the JIT never emits into instrumentation schemas, so crossgen2
and the R2R schema reader now reject them.

Replace the remaining alignment #ifdefs with a single PgoDataAlignment, and
size copied instrumentation data by the maximum record end in all builds.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The PR does not change the JIT-EE interface (corinfo.h, corjit.h and the thunks are untouched), and bumping the GUID makes superpmi-diffs skip asm diffs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move merging of a method's instrumentation allocations (ReadyToRun inlinee
copies and interpreter counters) from the runtime's shutdown logging into
dotnet-pgo create-mibc. The runtime again emits one event per allocation,
as on main. dotnet-pgo ignores unexecuted allocations, sums the rest with
PgoProcessor.Merge, and warns and skips methods mixing block and edge counts.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Handle histogram tables have a fixed number of slots and unfilled slots
hold a null handle. The JIT skips null handles, but crossgen2 maps them
to unknown type handles that count toward the total and dilute the
observed types, which suppressed guarded casts in the Browser
ReadyToRun type profile roundtrip. Keep only filled slots when merging
per-method instrumentation data.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Share MIBC creation and histogram sample extraction across the Browser
PGO tests, and drop the incompatible-profile test now covered by the
dotnet-pgo unit tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove dotnet-pgo --include-interpreted-rundown, the session-stop
capture-state rundown in the CoreCLR EventPipe provider, and the
EndEnumeration keyword from the browser PGO collector. ReadyToRun
instrumentation events already carry MethodDetails and BulkType records,
so the counter path does not need them. Interpreter block counts remain
available through DOTNET_InterpPGO.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The CoreCLR interpreter does not emit JIT instrumentation events, so methods
that only ran interpreted are missing from a Browser PGO profile unless
DOTNET_InterpPGO instruments them. Add create-mibc
--include-interpreted-rundown to select metadata-backed interpreted methods
from method-load/rundown events as method-presence roots, so the next
crossgen2 run can precompile them.

To resolve those code ranges, the CoreCLR EventPipe provider enumerates
capture state at session stop, and the browser PGO collector enables the
EndEnumeration keyword.

This reverts commit b2f67ca.

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

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/crossgen-contrib
See info in area-owners.md if you want to be subscribed.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants