Replies: 11 comments 14 replies
-
@methane ^^ |
Beta Was this translation helpful? Give feedback.
-
At one point in Matt's talk, he discusses a rejected cache-line-friendly design that requires 8-byte keys, and explicitly says that if he were designing a hash map for Python, he would use that design. (Note, however, that Python's insertion ordering guarantees make a lot of this stuff a bit trickier.) Basically, keys are collected in groups of seven, with the struct for each group looking something like: typedef struct {
uint8_t ever_full : 1;
uint8_t tombstones : 7;
uint8_t hashes[7]; // Low byte of each hash.
PyObject *keys[7];
} seven_keys; ...then use intrinsics on the first 8 bytes to probe for hits. |
Beta Was this translation helpful? Give feedback.
-
I impressed how they lookup value in a group: https://youtu.be/ncHmEUmJZf4?t=1739. Currently, our
Current:
Idea:
(When SSE2 can be used, we can use same idea for len<=16 hash.) |
Beta Was this translation helpful? Give feedback.
-
Is this discussion overlapping with #133 - could we relate or join these explicitly? revisiting #133 … also, there maybe performance trade-offs to consider depending on when and how we select the best fitting CPU instruction sets. I see four open issues in the aHash project that may be of interest here: |
Beta Was this translation helpful? Give feedback.
-
How would this hypothetical new design handle split dictionaries? |
Beta Was this translation helpful? Give feedback.
-
Yeah, it doesn't sound like this is going to be a killer change |
Beta Was this translation helpful? Give feedback.
-
For small dict-keys, it may well be faster to perform a linear scan over the keys. It is also a lot simpler than fancy SSE stuff. |
Beta Was this translation helpful? Give feedback.
-
One other possibility is to use bi-directional layout, as we do for the quickened code (and values array in python/cpython#31191). Now:
With bi-directional layout:
This removes the overhead of computing the offset of |
Beta Was this translation helpful? Give feedback.
-
But wouldn’t that leave two 4-byte holes? |
Beta Was this translation helpful? Give feedback.
-
I implemented Swisstable: methane/cpython#41
Swisstable hash reduces conflict. But it makes one more lookup layer. Swisstable hash is cache friendly, but our compact dict is cache friendly too. I suspend trying Swisstable. If someone interested in Swisstable, please try to change set, instead of dict.
|
Beta Was this translation helpful? Give feedback.
-
Thanks for trying that out. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I was reading about Rust's new hash table the other day, and found some articles about the hash table it derives from. Might be a good idea to look into this and incorporate some of the ideas, given how hot hash tables are in Python:
Beta Was this translation helpful? Give feedback.
All reactions