Skip to content

Commit 7e44607

Browse files
Abseil Teamdinord
authored andcommitted
Export of internal Abseil changes
-- 58affd6378c47993f5408f7b8a8863fa5bcc2c47 by Derek Mauro <[email protected]>: Internal change PiperOrigin-RevId: 403120541 -- 27dc5d5f87bca6254585cca69058c14e0a2f3ce6 by Chris Kennelly <[email protected]>: Prefetch while hashing. While we may not need to access the cacheline *ctrl_ is on once we've computed the hash, we can begin to resolve the TLB required for the hashtable's heap allocation simultaneously with computing the hash value for the key. PiperOrigin-RevId: 402954725 GitOrigin-RevId: 58affd6378c47993f5408f7b8a8863fa5bcc2c47 Change-Id: Id04297de823ad5c5a867c46065fa3a9ef0ada3dd
1 parent 22f482f commit 7e44607

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

absl/container/internal/raw_hash_set.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,7 @@ class raw_hash_set {
14461446
void prefetch(const key_arg<K>& key) const {
14471447
(void)key;
14481448
#if defined(__GNUC__)
1449+
prefetch_heap_block();
14491450
auto seq = probe(ctrl_, hash_ref()(key), capacity_);
14501451
__builtin_prefetch(static_cast<const void*>(ctrl_ + seq.offset()));
14511452
__builtin_prefetch(static_cast<const void*>(slots_ + seq.offset()));
@@ -1477,6 +1478,7 @@ class raw_hash_set {
14771478
}
14781479
template <class K = key_type>
14791480
iterator find(const key_arg<K>& key) {
1481+
prefetch_heap_block();
14801482
return find(key, hash_ref()(key));
14811483
}
14821484

@@ -1486,6 +1488,7 @@ class raw_hash_set {
14861488
}
14871489
template <class K = key_type>
14881490
const_iterator find(const key_arg<K>& key) const {
1491+
prefetch_heap_block();
14891492
return find(key, hash_ref()(key));
14901493
}
14911494

@@ -1856,6 +1859,7 @@ class raw_hash_set {
18561859
protected:
18571860
template <class K>
18581861
std::pair<size_t, bool> find_or_prepare_insert(const K& key) {
1862+
prefetch_heap_block();
18591863
auto hash = hash_ref()(key);
18601864
auto seq = probe(ctrl_, hash, capacity_);
18611865
while (true) {
@@ -1918,6 +1922,15 @@ class raw_hash_set {
19181922

19191923
size_t& growth_left() { return settings_.template get<0>(); }
19201924

1925+
void prefetch_heap_block() const {
1926+
// Prefetch the heap-allocated memory region to resolve potential TLB
1927+
// misses. This is intended to overlap with execution of calculating the
1928+
// hash for a key.
1929+
#if defined(__GNUC__)
1930+
__builtin_prefetch(static_cast<const void*>(ctrl_), 0, 1);
1931+
#endif // __GNUC__
1932+
}
1933+
19211934
HashtablezInfoHandle& infoz() { return settings_.template get<1>(); }
19221935

19231936
hasher& hash_ref() { return settings_.template get<2>(); }

0 commit comments

Comments
 (0)