Compute `hash_of(key)` before `common().capacity()` in `find_large` and `find_or_prepare_insert_large`. When `hash_of(key)` involves a conditional or non-inlined function call (such as string hashing calling `CombineLargeContiguousImplOn64BitLengthGt32` for strings `> 32B` or custom hash functors), evaluating `common().capacity()` before `hash_of(key)` forces the compiler to keep the computed capacity live across the call, spilling into callee-saved registers or stack slots. For inlined scalar hashes (`int64_t`), computing `common().capacity()` (`shlxq`/`bzhiq`) before `hash_of(key)` also delays starting the `crc32q` hash dependency chain by 1 cycle. Computing `hash_of(key)` before `common().capacity()` avoids keeping `capacity()` live across `hash_of(key)` and starts the `hash_of(key)` dependency chain immediately on table lookup entry. PiperOrigin-RevId: 1004969102
diff --git a/absl/container/internal/raw_hash_set.h b/absl/container/internal/raw_hash_set.h index ba34be9..ce8a1e4 100644 --- a/absl/container/internal/raw_hash_set.h +++ b/absl/container/internal/raw_hash_set.h
@@ -3619,9 +3619,9 @@ template <class K> iterator find_large(absl::type_identity_t<K> key) { static_assert(std::is_same_v<K, FindLargeKey<K>>); + const size_t hash = hash_of(key); const size_t cap = common().capacity(); ABSL_ASSUME(cap > kMaxSmallCapacity); - const size_t hash = hash_of(key); auto seq = probe(ProbeCapacity{cap}, hash); const h2_t h2 = H2(hash); ctrl_t* ctrl = control(); @@ -3897,8 +3897,8 @@ absl::type_identity_t<K> key) { static_assert(std::is_same_v<K, FindLargeKey<K>>); prefetch_heap_block(); - const size_t cap = capacity(); const size_t hash = hash_of(key); + const size_t cap = capacity(); auto seq = probe(ProbeCapacity{cap}, hash); const h2_t h2 = H2(hash); const ctrl_t* ctrl = control();