[libcxx-commits] [PATCH] D61878: [libc++] Optimize unordered_{multiset, multimap} equality comparison
Louis Dionne via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Sep 18 12:44:27 PDT 2023
ldionne updated this revision to Diff 556969.
ldionne added a comment.
Apply the optimization to non-multi containers too. Long story short, I am not convinced that these changes are a real improvement.
Indeed, map lookup starts by computing the hash of the key. If computing the hash is cheaper than fully comparing the key for equality, it can happen that using `std::mismatch` actually pessimizes the algorithm, since it always checks for full key equality.
Consequently, I am going to drop this patch and only cherry-pick some of the changes in this patch (e.g. testing improvements).
Before patch:
----------------------------------------------------------------------------------------------------
Benchmark Time CPU Iterations
----------------------------------------------------------------------------------------------------
BM_Compare_same_container/unordered_set_string/1024 155440 ns 155422 ns 4495
BM_Compare_same_container/unordered_set_int/1024 2501 ns 2501 ns 269041
BM_Compare_different_containers/unordered_set_string/1024 67.7 ns 67.7 ns 10428771
BM_Compare_different_containers/unordered_set_int/1024 1.33 ns 1.33 ns 528206212
BM_Compare_shared_prefix/unordered_set_string/1024 68.1 ns 68.1 ns 10355336
BM_Compare_shared_prefix/unordered_set_int/1024 1.33 ns 1.33 ns 527314912
After patch:
----------------------------------------------------------------------------------------------------
Benchmark Time CPU Iterations
----------------------------------------------------------------------------------------------------
BM_Compare_same_container/unordered_set_string/1024 153609 ns 153589 ns 4515
BM_Compare_same_container/unordered_set_int/1024 2390 ns 2390 ns 279170
BM_Compare_different_containers/unordered_set_string/1024 70.7 ns 70.7 ns 9918807
BM_Compare_different_containers/unordered_set_int/1024 3.11 ns 3.11 ns 173664520
BM_Compare_shared_prefix/unordered_set_string/1024 69.7 ns 69.7 ns 10042753
BM_Compare_shared_prefix/unordered_set_int/1024 1.44 ns 1.44 ns 486236047
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D61878/new/
https://reviews.llvm.org/D61878
Files:
libcxx/benchmarks/ContainerBenchmarks.h
libcxx/benchmarks/unordered_set_operations.bench.cpp
libcxx/include/unordered_map
libcxx/include/unordered_set
libcxx/test/std/containers/unord/unord.multimap/eq.pass.cpp
libcxx/test/std/containers/unord/unord.multiset/eq.pass.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61878.556969.patch
Type: text/x-patch
Size: 12658 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230918/be9ac1e9/attachment.bin>
More information about the libcxx-commits
mailing list