From 48abb9fe0eeaf0149f0351acb00201f07e79f293 Mon Sep 17 00:00:00 2001 From: Chris Kennelly Date: Mon, 25 Mar 2024 13:16:00 -0700 Subject: Record sizeof(key_type), sizeof(value_type) in hashtable profiles. This can identify situations where flat_hash_* is suboptimal for large elements. PiperOrigin-RevId: 618937993 Change-Id: I2bde069bc3526b14ad1718ba6f50467002aeed16 --- absl/container/internal/raw_hash_set.h | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'absl/container/internal/raw_hash_set.h') diff --git a/absl/container/internal/raw_hash_set.h b/absl/container/internal/raw_hash_set.h index 58188444..2b0337ef 100644 --- a/absl/container/internal/raw_hash_set.h +++ b/absl/container/internal/raw_hash_set.h @@ -1786,7 +1786,8 @@ constexpr bool ShouldSampleHashtablezInfo() { } template -HashtablezInfoHandle SampleHashtablezInfo(size_t sizeof_slot, +HashtablezInfoHandle SampleHashtablezInfo(size_t sizeof_slot, size_t sizeof_key, + size_t sizeof_value, size_t old_capacity, bool was_soo, HashtablezInfoHandle forced_infoz, CommonFields& c) { @@ -1794,12 +1795,12 @@ HashtablezInfoHandle SampleHashtablezInfo(size_t sizeof_slot, // In SOO, we sample on the first insertion so if this is an empty SOO case // (e.g. when reserve is called), then we still need to sample. if (kSooEnabled && was_soo && c.size() == 0) { - return Sample(sizeof_slot, SooCapacity()); + return Sample(sizeof_slot, sizeof_key, sizeof_value, SooCapacity()); } // For non-SOO cases, we sample whenever the capacity is increasing from zero // to non-zero. if (!kSooEnabled && old_capacity == 0) { - return Sample(sizeof_slot, 0); + return Sample(sizeof_slot, sizeof_key, sizeof_value, 0); } return c.infoz(); } @@ -1902,12 +1903,15 @@ class HashSetResizeHelper { template ABSL_ATTRIBUTE_NOINLINE bool InitializeSlots(CommonFields& c, Alloc alloc, - ctrl_t soo_slot_h2) { + ctrl_t soo_slot_h2, + size_t key_size, + size_t value_size) { assert(c.capacity()); HashtablezInfoHandle infoz = ShouldSampleHashtablezInfo() - ? SampleHashtablezInfo(SizeOfSlot, old_capacity_, - was_soo_, forced_infoz_, c) + ? SampleHashtablezInfo(SizeOfSlot, key_size, value_size, + old_capacity_, was_soo_, + forced_infoz_, c) : HashtablezInfoHandle{}; const bool has_infoz = infoz.IsSampled(); @@ -3362,7 +3366,8 @@ class raw_hash_set { inline HashtablezInfoHandle try_sample_soo() { assert(is_soo()); if (!ShouldSampleHashtablezInfo()) return HashtablezInfoHandle{}; - return Sample(sizeof(slot_type), SooCapacity()); + return Sample(sizeof(slot_type), sizeof(key_type), sizeof(value_type), + SooCapacity()); } inline void destroy_slots() { @@ -3458,7 +3463,8 @@ class raw_hash_set { resize_helper.InitializeSlots( - common(), CharAlloc(alloc_ref()), soo_slot_h2); + common(), CharAlloc(alloc_ref()), soo_slot_h2, sizeof(key_type), + sizeof(value_type)); // In the SooEnabled() case, capacity is never 0 so we don't check. if (!SooEnabled() && resize_helper.old_capacity() == 0) { -- cgit v1.2.3