-
-
Notifications
You must be signed in to change notification settings - Fork 536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New map
internals
#2181
Merged
Merged
New map
internals
#2181
Conversation
This file contains 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
…finition of `runtime.Raw_Map`
… `map`; add `runtime.map_get`
This is test code
Test code
gingerBill
requested review from
colrdavidson,
graphitemaster,
Kelimion and
oskarnp
November 11, 2022 16:12
map[K]struct{} works fine.
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.
High performance, cache-friendly, open-addressed Robin Hood hashing hash map data structure with various optimizations for Odin.
To make this map cache-friendly it uses a novel strategy to ensure keys and values of the map are always cache-line aligned and that no single key or value of any type ever straddles a cache-line. This cache efficiency makes for quick lookups because the linear-probe always addresses data in a cache friendly way. This is enabled through the use of a special meta-type called a
Map_Cell
which packs as many values of a given type into a local array adding internal padding to round toMAP_CACHE_LINE_SIZE
. One other benefit to storing the internal data in this manner is false sharing no longer occurs when using a map, enabling efficient concurrent access of the map data structure with minimal locking if desired.Notes:
-use-static-map-calls
to enable static callsThis map implementation makes extensive use of
uintptr
for representing sizes, lengths, capacities, masks, pointers, offsets, and addresses to avoid expensive sign extension and masking that would be generated if types were casted all over. The only place regular ints show up is in the cap() and len() implementations.Benefits of this approach over the old approach
alloc_non_zeroed
andfree
internallyruntime.Map_Info
) for dynamic callsdelete_key
whilst iterating across themap
Issues of this approach over the old approach
for in
loopGeneral differences
0
is not a valid hash value any more, it will be set to1
internallylog2(capacity)
is encoded into thedata
as the lowest 6 bits (allowing for a hypothetical maximum capacity of 2^63 elements)TODOs for Future PRs
fnv64a
, maybe somethingwyhash
might be betterwyhash
is being used by other languages as a fallback, and appears to perform well with smhasher