You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This ThreadLocalStorage class in WIL is a hand-rolled TLS like thing that stores state on a per-thread basis. It boils down to a simple fixed size hash table with 10 buckets, where the thread to bucket mapping is (thread-ID mod 10). Search for m_hashArray in result.h to find the code in question.
The bug here is that half of the buckets in these hash tables are never utilized, because thread IDs are never odd.
Dump any instance of one of these things and you will always see that the odd slots in the table are unused.
The low two bits for thread IDs seem to never be set. This code could would be better off shifting the thread ID right by two before doing the mod. All buckets would be used, and the length of the hash chains would be cut in half. size_t const index = ((threadId >> 2) % ARRAYSIZE(m_hashArray));
I moved this from http://task.ms/51574898 here in case someone is willing to pick up this fix.
The text was updated successfully, but these errors were encountered:
ChrisGuzak
changed the title
WIL : Poor bucketing behavior in ThreadLocalStorage<T> (half the hash table goes unused)
Poor bucketing behavior in ThreadLocalStorage<T> (half the hash table goes unused)
Dec 20, 2024
This ThreadLocalStorage class in WIL is a hand-rolled TLS like thing that stores state on a per-thread basis. It boils down to a simple fixed size hash table with 10 buckets, where the thread to bucket mapping is (thread-ID mod 10). Search for m_hashArray in result.h to find the code in question.
The bug here is that half of the buckets in these hash tables are never utilized, because thread IDs are never odd.
Dump any instance of one of these things and you will always see that the odd slots in the table are unused.
This would dump all instances in the process:
The low two bits for thread IDs seem to never be set. This code could would be better off shifting the thread ID right by two before doing the mod. All buckets would be used, and the length of the hash chains would be cut in half.
size_t const index = ((threadId >> 2) % ARRAYSIZE(m_hashArray));
I moved this from http://task.ms/51574898 here in case someone is willing to pick up this fix.
The text was updated successfully, but these errors were encountered: