Repository navigation
Compress runtime-class hierarchy with UTF-16 prefixes and narrow buckets - #2648
Open
Manodasan Wignarajah (manodasanW) wants to merge 1 commit into
Open
Manodasan Wignarajah (manodasanW) wants to merge 1 commit into
Manodasan Wignarajah (manodasanW) wants to merge 1 commit into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reduce runtime-class hierarchy lookup size using shared UTF-16 namespace prefixes and conditional 16-bit bucket offsets. Preserve every hierarchy entry, existing lookup semantics and allocation-free base-name spans.
Motivation
Fully qualified class names repeat the same namespaces throughout the hierarchy table. Sharing those prefixes reduces readonly data.
Changes
WindowsRuntimeTypeHierarchyBuilder.cs: emit each namespace prefix once and store a prefix offset plus class-name suffix in each key. Use 16-bit bucket offsets when the complete key payload fits safely alongside the reserved empty-bucket sentinel; otherwise retain 32-bit offsets.WindowsRuntimeTypeHierarchy.cs: compare prefix and suffix directly against input slices using ordinal UTF-16 comparisons. Use the generated bucket accessor to hide the selected offset width.Full-name hashing, bucket counts, collision chains and contiguous UTF-16 base values remain unchanged. No names are reconstructed or allocated during lookup.
Before and after example
Previously, each key stored the complete class name, repeating its namespace:
The new layout stores that namespace once:
This is an illustrative layout: lengths count UTF-16 characters,
P0represents a byte offset into the prefix table, and the base-value offsets are unchanged. Matching compares the namespace and suffix separately against the original input.For ContosoCamera, prefix sharing reduces the key payload from 97,272 to 46,916 bytes, enabling narrow buckets. The same 1,526 bucket entries then occupy 3,052 bytes instead of 6,104 bytes. Larger catalogs automatically retain 32-bit entries.
Measurements
ContosoCamera was republished unchanged using matching configurations and tools. Size measurements include all hierarchy payloads and retained lookup helpers.
This reduces hierarchy data by 42.8% and the native executable by 50 KiB. Native AOT timings are warmed harness measurements on Windows x64 with .NET 10.0.14, not application startup measurements.
Validation
Buttonprojection still resolves to the survivingDependencyObjectwrapper.