Skip to content

[cDAC] Select one authoritative layout per IData instance - #136851

Merged
max-charlamb merged 2 commits into
dotnet:mainfrom
max-charlamb:cdac-whole-layout-selection
Nov 5, 2026
Merged

max-charlamb merged 2 commits into
dotnet:mainfrom
max-charlamb:cdac-whole-layout-selection

Conversation

@max-charlamb

Copy link
Copy Markdown
Member

Summary

Select one authoritative layout for each generated IData instance. Try all candidate type names against native descriptors first; only when none exists, resolve a managed layout lazily. Missing fields or size never cause another layout to be consulted. Optional fields remain absent, and required fields or size throw when accessed.

This removes unnecessary managed type-name scans for missing optional native fields, such as MethodTable.InterfaceMap, and replaces the per-instance layout list and array with one layout holder. Static, thread-static, and type-handle resolution remain independent.

Explicitly capture the CoreLib assembly root in MemoryEnumerator.EnumerateStatics(). Managed fallback previously captured this pointer incidentally; later analysis of the resulting dump can still legitimately need it. Keep this read independently best-effort so an unavailable Loader or RuntimeTypeSystem does not prevent the other static reads.

Update the IData documentation and add regression coverage for layout priority, required and optional fields, writes, field addresses, offsets, instance size, lazy managed resolution, and dump-root preservation.

Performance

Fresh Windows x64 heap-enumeration measurements, in milliseconds:

Workload Native DAC cDAC baseline cDAC with whole-layout selection Reduction
SmallSimple 1.637 3.692 2.423 34.4%
LargeSimple 1.656 3.521 2.480 29.6%
SmallComplex 3.087 5.240 4.139 21.0%
LargeComplex 9.372 13.016 11.458 12.0%
CodeHeavy 3.463 5.696 4.545 20.2%
DeepStacks 11.139 15.921 14.458 9.2%

These are means of 90 retained measurements per case: three process launches with 30 measurements each, with no outlier removal. Both cDAC providers include the same other optimizations from #136598, #136589, #136600, #136611, #136646, and #136661. This is a combined-optimizations experiment, not an isolated comparison against current main; this PR does not include those other changes.

Measurements ran on a shared Hyper-V host and exclude instance creation, flush/setup, and release. The target dumps lack optional MethodTable.InterfaceMap; benefits on newer targets can differ. Legitimate metadata reads, including exception type-name resolution, remain unchanged.

Validation

After rebasing this change independently onto current main:

  • Generator suite: 57 passed, no failures or skips.
  • Reader suite: 3,909 passed, no failures or skips.
  • Windows x64 NativeAOT enumerator publish: succeeded.
  • Freshly published PR provider: all 18 Mini/Heap/Triage cases exactly match baseline memory ranges and updates, including the CoreLib assembly root.

The test and publish invocations used the repository-local SDK:

$results = 'artifacts\dump-perf\whole-layout-production-20261102'
.\.dotnet\dotnet.exe test src\native\managed\cdac\tests\DataGenerator\Microsoft.Diagnostics.DataContractReader.DataGenerator.Tests.csproj -c Release -m:1 -p:BuildInParallel=false --logger 'trx;LogFileName=generator-main.trx' --results-directory "$results\pr-tests"
.\.dotnet\dotnet.exe test src\native\managed\cdac\tests\UnitTests\Microsoft.Diagnostics.DataContractReader.Tests.csproj -c Release -m:1 -p:BuildInParallel=false --logger 'trx;LogFileName=unit-main.trx' --results-directory "$results\pr-tests"
.\.dotnet\dotnet.exe publish src\native\managed\cdac\mscordaccore_enummemory\mscordaccore_enummemory.csproj -c Release -r win-x64 --self-contained -m:1 -p:BuildInParallel=false -p:NativeLib=Shared -p:IsRuntimeComponent=false -o "$results\pr-enumerator"

In the combined-optimizations experiment, all 18 dump cases also completed with fail-fast guards forbidding managed layout lookup and full managed type-name search. Six named stack-walk cases matched native DAC exactly, with cold/warm equality. The four architecture-specific dump-root regression cases were verified to fail when the explicit root read was removed.

Note

This PR description and implementation were developed with GitHub Copilot.

Prefer a complete native layout when available and use lazy managed lookup only when no native layout exists. Preserve the CoreLib assembly root explicitly during dump enumeration and cover whole-layout selection with regression tests.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: de3eab4e-b090-430a-8e30-6b204fb1519a
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
10 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.

@max-charlamb
max-charlamb requested a review from rcj1 November 2, 2026 17:27
@rcj1

rcj1 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

We could probably remove LayoutSet now that we only resolve max one layout.

Represent each generated IData layout with a single TypeLayout helper and update CdacUsageGraph to recognize the renamed generated helper.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: de3eab4e-b090-430a-8e30-6b204fb1519a
@max-charlamb

Copy link
Copy Markdown
Member Author

/ba-g helix monitor failure

@max-charlamb
max-charlamb merged commit 0282f9b into dotnet:main Nov 5, 2026
91 of 97 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 6, 2026
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