Use NonZeroU64 for Id<T> to enable niche optimization on Option<Id>#659
Draft
st0012 wants to merge 1 commit intooptimize-name-depth-sortingfrom
Draft
Use NonZeroU64 for Id<T> to enable niche optimization on Option<Id>#659st0012 wants to merge 1 commit intooptimize-name-depth-sortingfrom
st0012 wants to merge 1 commit intooptimize-name-depth-sortingfrom
Conversation
Change Id<T> from u64 to NonZeroU64 so that Option<Id<T>> is 8 bytes instead of 16 bytes. Hash value 0 is remapped to u64::MAX (the collision probability is 2^-64, same as any other hash collision). This propagates savings through every struct with an Option<XxxId> field: - MethodRef: 40 → 32 bytes (receiver: Option<NameId>) - Name: 48 → 40 bytes (nesting: Option<NameId>) - ClassDefinition: 144 → 128 bytes (two Option<Id> fields) - All other definition structs: -8 bytes each (lexical_nesting_id) - Namespace declarations: 224 → 216 bytes (singleton_class_id) ## Benchmark | Metric | Before | After | Delta | |--------|--------|-------|-------| | Memory (peak footprint) | 4480 MB | 3978 MB | -11.2% | | Declarations | 895,844 | 895,844 | identical | | Definitions | 1,063,171 | 1,063,171 | identical |
f936bb1 to
12f4741
Compare
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
Id<T>fromu64toNonZeroU64so thatOption<Id<T>>is 8 bytes instead of 16 bytesu64::MAX(collision probability is 2^-64, same as any other hash collision)Option<XxxId>field:Benchmark