Skip to content

Flatten NativeAOT reflection metadata namespaces - #135847

Merged
MichalStrehovsky merged 6 commits into
dotnet:mainfrom
MichalStrehovsky:nativeaot-flat-namespace-metadata
Oct 21, 2026
Merged

MichalStrehovsky merged 6 commits into
dotnet:mainfrom
MichalStrehovsky:nativeaot-flat-namespace-metadata

Conversation

@MichalStrehovsky

@MichalStrehovsky MichalStrehovsky commented Oct 15, 2026 •

Copy link
Copy Markdown
Member
  • Instead of storing namespaces per . separate part, store as entire string.
  • Store TypeDefinitions/TypeForwards in a hashtable to eliminate perf impact (per-namespace-part representation could have a somewhat better performance in lookups than storing all types in a single collection, but hashtable will beat that).

MichalStrehovsky and others added 2 commits October 15, 2026 16:53
Replace namespace trees with shared full-name records and scope-level type and forwarder lists. Regenerate metadata readers and writers, migrate NativeAOT consumers, and remove NamespaceChain.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 070f14d8-a6c1-4b56-b431-ee470872268a
Reuse decoded scope records and immutable assembly identities through the existing per-scope dispenser. Cache named-type namespace handles to avoid repeated enclosing-type walks while preserving canonical assembly rebinding.

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

Copilot-Session: 070f14d8-a6c1-4b56-b431-ee470872268a
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 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: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.

@MichalStrehovsky

Copy link
Copy Markdown
Member Author

3c2faff is one of the reasons why I don't like native AOT metadata format being variable-length - the ScopeDefinition constructor now needs to decode the handle list of all TypeDefinitions in the assembly even if we only need to know name or flags because of how this metadata is constructed and the impossibility of indexing into a record.

MichalStrehovsky and others added 2 commits October 15, 2026 21:24
This reverts commit 3c2faff.

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

Copilot-Session: 070f14d8-a6c1-4b56-b431-ee470872268a
Move top-level type definitions and forwarders behind a TypeDefinitionGroup handle so scalar scope reads do not traverse these collections. Regenerate metadata readers and writers and update transform and reflection consumers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 070f14d8-a6c1-4b56-b431-ee470872268a
Store top-level type definitions and forwarders in schema-generated native hashtables using version-resilient UTF-8 name hashes. Keep nested collections linear and remove the redundant TypeDefinitionGroup indirection.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b001f6bf-f70d-4bbf-868c-7d12aec8f113
@jkotas

jkotas commented Oct 19, 2026

Copy link
Copy Markdown
Member

/azp run runtime-nativeaot-outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The metadata-format migration needs human review, NativeAOT validation, measurements, and resolution of the forwarder regression.

1 open issue
What changed in this PR

Flattens NativeAOT reflection namespaces into full names and scope references, replacing namespace-tree traversal with assembly-level type tables.

Changes:

  • Adds generated hash tables for type definitions and forwarders.
  • Updates metadata producers, reflection lookup, and name formatting.
  • Adds character-span hashing and removes namespace-chain infrastructure.

Builds, tests, and measurements were not run.

File Description
src/​libraries/​Common/​src/​Internal/​VersionResilientHashCode.cs Adds character-span name hashing.
src/​coreclr/​tools/​Common/​Internal/​Metadata/​NativeFormat/​NativeFormatReaderGen.cs Updates generated records and hash-table readers.
src/​coreclr/​tools/​Common/​Internal/​Metadata/​NativeFormat/​MetadataTypeHashingAlgorithms.cs Hashes flattened namespace names.
src/​coreclr/​tools/​Common/​Internal/​Metadata/​NativeFormat/​MdBinaryReaderGen.cs Reads hash-table references.
src/​coreclr/​tools/​Common/​Internal/​Metadata/​NativeFormat/​Generator/​WriterGen.cs Generates hash-table placement and serialization.
src/​coreclr/​tools/​Common/​Internal/​Metadata/​NativeFormat/​Generator/​SchemaDef.cs Defines flattened namespaces and scope tables.
src/​coreclr/​tools/​Common/​Internal/​Metadata/​NativeFormat/​Generator/​ReaderGen.cs Generates typed hash-table enumerators.
src/​coreclr/​tools/​Common/​Internal/​Metadata/​NativeFormat/​Generator/​MdBinaryReaderGen.cs Generates hash-table decoding.
src/​coreclr/​tools/​aot/​ILCompiler.MetadataTransform/​Internal/​Metadata/​NativeFormat/​Writer/​NativeMetadataWriter.cs Places tables and computes lookup hashes.
src/​coreclr/​tools/​aot/​ILCompiler.MetadataTransform/​Internal/​Metadata/​NativeFormat/​Writer/​NativeFormatWriterGen.cs Updates generated metadata writers.
src/​coreclr/​tools/​aot/​ILCompiler.MetadataTransform/​ILCompiler/​Metadata/​Transform.TypeForwarders.cs Associates forwarders with destination namespaces.
src/​coreclr/​tools/​aot/​ILCompiler.MetadataTransform/​ILCompiler/​Metadata/​Transform.Type.cs Registers top-level types on scopes.
src/​coreclr/​tools/​aot/​ILCompiler.MetadataTransform/​ILCompiler/​Metadata/​Transform.Namespace.cs Creates flattened namespace records.
src/​coreclr/​tools/​aot/​ILCompiler.MetadataTransform/​ILCompiler.MetadataTransform.csproj Includes shared hashing code.
src/​coreclr/​tools/​aot/​ILCompiler.Compiler/​Compiler/​UsageBasedMetadataManager.cs Changes unresolved-forwarder retention.
src/​coreclr/​tools/​aot/​ILCompiler.Compiler/​Compiler/​AnalysisBasedMetadataManager.cs Changes analysis-based forwarder retention.
src/​coreclr/​nativeaot/​System.Private.TypeLoader/​src/​Internal/​Runtime/​TypeLoader/​MetadataNameExtensions.cs Reads direct namespace names and scopes.
src/​coreclr/​nativeaot/​System.Private.StackTraceMetadata/​src/​Internal/​StackTraceMetadata/​StackTraceMetadata.cs Updates attribute matching and scope access.
src/​coreclr/​nativeaot/​System.Private.StackTraceMetadata/​src/​Internal/​StackTraceMetadata/​MethodNameFormatter.cs Formats flattened namespace names.
src/​coreclr/​nativeaot/​System.Private.CoreLib/​src/​System/​Reflection/​Runtime/​TypeInfos/​NativeFormat/​NativeFormatRuntimeNamedTypeInfo.cs Uses direct scopes and caches namespace strings.
src/​coreclr/​nativeaot/​System.Private.CoreLib/​src/​System/​Reflection/​Runtime/​General/​TypeResolver.NativeFormat.cs Resolves namespace scopes directly.
src/​coreclr/​nativeaot/​System.Private.CoreLib/​src/​System/​Reflection/​Runtime/​General/​NamespaceChain.cs Removes namespace-chain caching.
src/​coreclr/​nativeaot/​System.Private.CoreLib/​src/​System/​Reflection/​Runtime/​General/​MetadataReaderExtensions.NativeFormat.cs Simplifies namespace helpers and table enumeration.
src/​coreclr/​nativeaot/​System.Private.CoreLib/​src/​System/​Reflection/​Runtime/​Assemblies/​NativeFormat/​NativeFormatRuntimeAssembly.GetTypeCore.CaseSensitive.cs Uses hashed type lookup.
src/​coreclr/​nativeaot/​System.Private.CoreLib/​src/​System/​Reflection/​Runtime/​Assemblies/​NativeFormat/​NativeFormatRuntimeAssembly.GetTypeCore.CaseInsensitive.cs Builds lookup dictionaries from scope tables.
src/​coreclr/​nativeaot/​System.Private.CoreLib/​src/​System/​Reflection/​Runtime/​Assemblies/​NativeFormat/​NativeFormatRuntimeAssembly.cs Enumerates types and forwarders from scopes.
src/​coreclr/​nativeaot/​System.Private.CoreLib/​src/​System.Private.CoreLib.csproj Updates shared-source inclusion.
src/​coreclr/​nativeaot/​System.Private.CoreLib/​src/​CompatibilitySuppressions.xml Aligns suppressions with generated types.

Review effort: Balanced

@MichalStrehovsky
MichalStrehovsky marked this pull request as ready for review October 20, 2026 01:00
@MichalStrehovsky

Copy link
Copy Markdown
Member Author

/azp run runtime-nativeaot-outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

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

Copilot-Session: 71dd5c69-d5b1-4974-89c6-79d586102144

@jkotas jkotas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@MichalStrehovsky
MichalStrehovsky merged commit af81846 into dotnet:main Oct 21, 2026
125 checks passed
@MichalStrehovsky
MichalStrehovsky deleted the nativeaot-flat-namespace-metadata branch October 21, 2026 08:20
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 22, 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.

3 participants