From a936dfe8a5fda03dc25da1d247c792eee8f48fe2 Mon Sep 17 00:00:00 2001 From: Roman Gershman Date: Sun, 19 Jan 2025 20:07:22 +0200 Subject: [PATCH] chore: add Dash::Prefetch function (#4476) * chore: add Dash::Prefetch function It's not being used at this time. * chore: fixes --- src/core/dash.h | 11 +++++++++++ src/core/dash_internal.h | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/core/dash.h b/src/core/dash.h index 0c67fd6b2..05a99560f 100644 --- a/src/core/dash.h +++ b/src/core/dash.h @@ -149,6 +149,9 @@ class DashTable : public detail::DashTableBase { template const_iterator Find(U&& key) const; template iterator Find(U&& key); + // Prefetches the memory where the key would resize into the cache. + template void Prefetch(U&& key) const; + // Find first entry with given key hash that evaulates to true on pred. // Pred accepts either (const key&) or (const key&, const value&) template iterator FindFirst(uint64_t key_hash, Pred&& pred); @@ -699,6 +702,14 @@ auto DashTable<_Key, _Value, Policy>::Find(U&& key) -> iterator { return FindFirst(DoHash(key), EqPred(key)); } +template +template +void DashTable<_Key, _Value, Policy>::Prefetch(U&& key) const { + uint64_t key_hash = DoHash(key); + uint32_t seg_id = SegmentId(key_hash); + segment_[seg_id]->Prefetch(key_hash); +} + template template auto DashTable<_Key, _Value, Policy>::FindFirst(uint64_t key_hash, Pred&& pred) -> iterator { diff --git a/src/core/dash_internal.h b/src/core/dash_internal.h index 25981140d..418ec4963 100644 --- a/src/core/dash_internal.h +++ b/src/core/dash_internal.h @@ -502,6 +502,7 @@ template Iterator FindIt(Hash_t key_hash, Pred&& pred) const; + void Prefetch(Hash_t key_hash) const; // Returns valid iterator if succeeded or invalid if not (it's full). // Requires: key should be not present in the segment. @@ -1188,6 +1189,15 @@ auto Segment::FindIt(Hash_t key_hash, Pred&& pred) const -> return Iterator{}; } +template +void Segment::Prefetch(Hash_t key_hash) const { + uint8_t bidx = BucketIndex(key_hash); + const Bucket& target = bucket_[bidx]; + + // Prefetch the home bucket that might hold the key with high probability. + __builtin_prefetch(&target, 0, 1); +} + template template void Segment::TraverseAll(Cb&& cb) const {