diff options
| author | Dan Engelbrecht <[email protected]> | 2023-08-21 13:41:22 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-08-21 13:41:22 +0200 |
| commit | 574afd9a5c286883ab40ff2ecb2cb229d7786712 (patch) | |
| tree | de98edde994699d38e045104778cee651e9ffe23 | |
| parent | use robinmap in compact cas (#368) (diff) | |
| download | zen-574afd9a5c286883ab40ff2ecb2cb229d7786712.tar.xz zen-574afd9a5c286883ab40ff2ecb2cb229d7786712.zip | |
use better hash function for better distribution in IoBuffer g_MappingLocks (#370)
* use better hash function for better distribution in IoBuffer g_MappingLocks
* changelog
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | src/zencore/iobuffer.cpp | 11 |
2 files changed, 11 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 50535d9bf..b55b37448 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - Improvement: Windows: Cache process handles for FormatPackageMessage reducing function execution time from 100+us to ~1 us - Improvement: Skip upstream logic early if we have no upstream endpoints - Improvement: Cachestore logging of CbObjects are now async +- Improvement: Use better hashing algorithm for instance pointers when using shared lock in IoBufferExtendedCore::Materialize - Improvement: Use tsl/robin-map/robin-set in compactcas and projectstore for 30% faster GC ## 0.2.16 diff --git a/src/zencore/iobuffer.cpp b/src/zencore/iobuffer.cpp index f53d80778..22bc61395 100644 --- a/src/zencore/iobuffer.cpp +++ b/src/zencore/iobuffer.cpp @@ -249,11 +249,20 @@ static_assert(IsPow2(MappingLockCount), "MappingLockCount must be power of two") static RwLock g_MappingLocks[MappingLockCount]; +static uint64_t +HashPtr64(uint64_t x) +{ + x = (x ^ (x >> 30)) * UINT64_C(0xbf58476d1ce4e5b9); + x = (x ^ (x >> 27)) * UINT64_C(0x94d049bb133111eb); + x = x ^ (x >> 31); + return x; +} + static RwLock& MappingLockForInstance(const IoBufferExtendedCore* instance) { intptr_t base = (intptr_t)instance; - size_t lock_index = ((base >> 5) ^ (base >> 13)) & (MappingLockCount - 1u); + uint32_t lock_index = uint32_t(HashPtr64(uint64_t(base)) & (MappingLockCount - 1u)); return g_MappingLocks[lock_index]; } |