Skip to content

Commit 2aa00ab

Browse files
Abseil Teamderekmauro
authored andcommitted
Export of internal Abseil changes
-- 0acc8470116819a62fd5ebbc2c64fdd703c93331 by Abseil Team <[email protected]>: Add an attribute to HashtablezInfo which performs a bitwise XOR on all hashes. The purposes of this attribute is to identify if identical hash tables are being created. If we see a large number of identical tables, it's likely the code can be improved by using a common table as opposed to keep rebuilding the same one. PiperOrigin-RevId: 356338043 GitOrigin-RevId: 0acc8470116819a62fd5ebbc2c64fdd703c93331 Change-Id: If7d0a96629144fb41e6bef1ec93345a22df40733
1 parent c36d825 commit 2aa00ab

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

absl/container/internal/hashtablez_sampler.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ void HashtablezInfo::PrepareForSampling() {
7272
total_probe_length.store(0, std::memory_order_relaxed);
7373
hashes_bitwise_or.store(0, std::memory_order_relaxed);
7474
hashes_bitwise_and.store(~size_t{}, std::memory_order_relaxed);
75+
hashes_bitwise_xor.store(0, std::memory_order_relaxed);
7576

7677
create_time = absl::Now();
7778
// The inliner makes hardcoded skip_count difficult (especially when combined
@@ -235,6 +236,7 @@ void RecordInsertSlow(HashtablezInfo* info, size_t hash,
235236

236237
info->hashes_bitwise_and.fetch_and(hash, std::memory_order_relaxed);
237238
info->hashes_bitwise_or.fetch_or(hash, std::memory_order_relaxed);
239+
info->hashes_bitwise_xor.fetch_xor(hash, std::memory_order_relaxed);
238240
info->max_probe_length.store(
239241
std::max(info->max_probe_length.load(std::memory_order_relaxed),
240242
probe_length),

absl/container/internal/hashtablez_sampler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ struct HashtablezInfo {
7878
std::atomic<size_t> total_probe_length;
7979
std::atomic<size_t> hashes_bitwise_or;
8080
std::atomic<size_t> hashes_bitwise_and;
81+
std::atomic<size_t> hashes_bitwise_xor;
8182

8283
// `HashtablezSampler` maintains intrusive linked lists for all samples. See
8384
// comments on `HashtablezSampler::all_` for details on these. `init_mu`

absl/container/internal/hashtablez_sampler_test.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ TEST(HashtablezInfoTest, PrepareForSampling) {
8989
EXPECT_EQ(info.total_probe_length.load(), 0);
9090
EXPECT_EQ(info.hashes_bitwise_or.load(), 0);
9191
EXPECT_EQ(info.hashes_bitwise_and.load(), ~size_t{});
92+
EXPECT_EQ(info.hashes_bitwise_xor.load(), 0);
9293
EXPECT_GE(info.create_time, test_start);
9394

9495
info.capacity.store(1, std::memory_order_relaxed);
@@ -98,6 +99,7 @@ TEST(HashtablezInfoTest, PrepareForSampling) {
9899
info.total_probe_length.store(1, std::memory_order_relaxed);
99100
info.hashes_bitwise_or.store(1, std::memory_order_relaxed);
100101
info.hashes_bitwise_and.store(1, std::memory_order_relaxed);
102+
info.hashes_bitwise_xor.store(1, std::memory_order_relaxed);
101103
info.create_time = test_start - absl::Hours(20);
102104

103105
info.PrepareForSampling();
@@ -109,6 +111,7 @@ TEST(HashtablezInfoTest, PrepareForSampling) {
109111
EXPECT_EQ(info.total_probe_length.load(), 0);
110112
EXPECT_EQ(info.hashes_bitwise_or.load(), 0);
111113
EXPECT_EQ(info.hashes_bitwise_and.load(), ~size_t{});
114+
EXPECT_EQ(info.hashes_bitwise_xor.load(), 0);
112115
EXPECT_GE(info.create_time, test_start);
113116
}
114117

@@ -133,14 +136,17 @@ TEST(HashtablezInfoTest, RecordInsert) {
133136
EXPECT_EQ(info.max_probe_length.load(), 6);
134137
EXPECT_EQ(info.hashes_bitwise_and.load(), 0x0000FF00);
135138
EXPECT_EQ(info.hashes_bitwise_or.load(), 0x0000FF00);
139+
EXPECT_EQ(info.hashes_bitwise_xor.load(), 0x0000FF00);
136140
RecordInsertSlow(&info, 0x000FF000, 4 * kProbeLength);
137141
EXPECT_EQ(info.max_probe_length.load(), 6);
138142
EXPECT_EQ(info.hashes_bitwise_and.load(), 0x0000F000);
139143
EXPECT_EQ(info.hashes_bitwise_or.load(), 0x000FFF00);
144+
EXPECT_EQ(info.hashes_bitwise_xor.load(), 0x000F0F00);
140145
RecordInsertSlow(&info, 0x00FF0000, 12 * kProbeLength);
141146
EXPECT_EQ(info.max_probe_length.load(), 12);
142147
EXPECT_EQ(info.hashes_bitwise_and.load(), 0x00000000);
143148
EXPECT_EQ(info.hashes_bitwise_or.load(), 0x00FFFF00);
149+
EXPECT_EQ(info.hashes_bitwise_xor.load(), 0x00F00F00);
144150
}
145151

146152
TEST(HashtablezInfoTest, RecordErase) {

0 commit comments

Comments
 (0)