Fields

hardware None
os None

Parameters

Fields

NameValue

Parameters

NameValue
git_commit commit 3efa461d45a1867cf03d30bd4b6caf1ed2260475
Author: xbcnn <30337500+xbcnn@users.noreply.github.com>
Date: Thu Jul 3 15:39:06 2025 +0800

[libcxx] Avoid hash key in __hash_table::find() if it is empty. (#126837)

If the hash table is empty, with or without buckets, the find() can do
fast return. Then computing hash key is useless and avoidable, since it
could be expensive for some key types, such as long strings.

This is a small optimization but useful in cases like a checklist
(unordered_set/map) which is mostly empty.

```
For std::unordered_set<*>, `--benchmark_filter=find`
1. With the opt:

---------------------------------------------------------------------------------------------------------
Benchmark Time CPU Iterations
---------------------------------------------------------------------------------------------------------
std::unordered_set<int>::find(key) (existent)/0 0.118 ns 0.118 ns 5939922720
std::unordered_set<int>::find(key) (existent)/32 52.1 ns 52.1 ns 13287232
std::unordered_set<int>::find(key) (existent)/1024 51.1 ns 51.1 ns 13449472
std::unordered_set<int>::find(key) (existent)/8192 53.1 ns 53.1 ns 13420864
std::unordered_set<int>::find(key) (non-existent)/0 14.7 ns 14.7 ns 47725472
std::unordered_set<int>::find(key) (non-existent)/32 44.1 ns 44.1 ns 15478144
std::unordered_set<int>::find(key) (non-existent)/1024 41.2 ns 41.2 ns 15082464
std::unordered_set<int>::find(key) (non-existent)/8192 49.5 ns 49.5 ns 15233600
std::unordered_set<std::string>::find(key) (existent)/0 0.136 ns 0.136 ns 5157977920
std::unordered_set<std::string>::find(key) (existent)/32 739 ns 739 ns 1023744
std::unordered_set<std::string>::find(key) (existent)/1024 836 ns 836 ns 840448
std::unordered_set<std::string>::find(key) (existent)/8192 768 ns 768 ns 1085664
std::unordered_set<std::string>::find(key) (non-existent)/0 14.6 ns 14.6 ns 47844160
std::unordered_set<std::string>::find(key) (non-existent)/32 608 ns 608 ns 1106496
std::unordered_set<std::string>::find(key) (non-existent)/1024 646 ns 646 ns 986272
std::unordered_set<std::string>::find(key) (non-existent)/8192 669 ns 669 ns 1047584


2. Without the opt:

---------------------------------------------------------------------------------------------------------
Benchmark Time CPU Iterations
---------------------------------------------------------------------------------------------------------
std::unordered_set<int>::find(key) (existent)/0 0.135 ns 0.135 ns 5188502304
std::unordered_set<int>::find(key) (existent)/32 54.4 ns 54.4 ns 12954144
std::unordered_set<int>::find(key) (existent)/1024 57.7 ns 57.7 ns 13107008
std::unordered_set<int>::find(key) (existent)/8192 50.7 ns 50.7 ns 12953312
std::unordered_set<int>::find(key) (non-existent)/0 16.1 ns 16.1 ns 43460192
std::unordered_set<int>::find(key) (non-existent)/32 45.8 ns 45.8 ns 17139584
std::unordered_set<int>::find(key) (non-existent)/1024 44.6 ns 44.6 ns 16538048
std::unordered_set<int>::find(key) (non-existent)/8192 41.5 ns 41.5 ns 12850816
std::unordered_set<std::string>::find(key) (existent)/0 0.133 ns 0.133 ns 5214104992
std::unordered_set<std::string>::find(key) (existent)/32 731 ns 731 ns 1000576
std::unordered_set<std::string>::find(key) (existent)/1024 716 ns 716 ns 1131584
std::unordered_set<std::string>::find(key) (existent)/8192 745 ns 745 ns 909632
std::unordered_set<std::string>::find(key) (non-existent)/0 600 ns 600 ns 1089792
std::unordered_set<std::string>::find(key) (non-existent)/32 645 ns 645 ns 979232
std::unordered_set<std::string>::find(key) (non-existent)/1024 675 ns 675 ns 962240
std::unordered_set<std::string>::find(key) (non-existent)/8192 711 ns 711 ns 1054880

```

We can see the improvements when find() for non-existent
`std::string`(random size 1~1024) keys:
```
std::unordered_set<std::string>::find(key) (non-existent)/0 14.6 ns 14.6 ns 47844160
std::unordered_set<std::string>::find(key) (non-existent)/0 600 ns 600 ns 1089792
```

---------

Co-authored-by: yangxiaobing <yangxiaobing@jwzg.com>
Filter

ldionne-old-macbook-results test results

Run Order Start Time Duration
Current 543274 2025-12-16T16:40:01 0:00:00
Previous 543222 2025-12-16T16:40:01 0:00:00
Baseline 485288 2025-12-16T16:40:01 0:00:00


Tests Summary

Status Group # # (B)
Performance Regressions 2 0
Performance Improvements 2 0
Added Tests 0 17
Unchanged Tests 81 68
Total Tests 85

Performance Regressions - execution_time Δ Previous Current σ Δ (B) σ (B)
710_omnetpp_r 2.67% 8.497 8.724 - 0.00% -
735_gem5_r 1.16% 14.011 14.174 - 0.00% -

Performance Improvements - execution_time Δ Previous Current σ Δ (B) σ (B)
727_cppcheck_r -1.85% 25.495 25.024 - 0.00% -
729_abc_r -1.13% 19.002 18.787 - 0.00% -

Added Tests - execution_time
706_stockfish_r
707_ntest_r
709_cactus_r
710_omnetpp_r
721_gcc_r
723_llvm_r
727_cppcheck_r
729_abc_r
731_astcenc_r
734_vpr_r
735_gem5_r
736_ocio_r
737_gmsh_r
748_flightdm_r
750_sealcrypto_r
753_ns3_r
766_femflow_r


Report Time: 0.20s
Name Current %
706_stockfish_r 22.237 -
707_ntest_r 18.088 -
709_cactus_r 19.787 -
710_omnetpp_r 8.724 2.67%
721_gcc_r 13.122 -
723_llvm_r 11.552 -
727_cppcheck_r 25.024 -1.85%
729_abc_r 18.787 -1.13%
731_astcenc_r 10.096 -
734_vpr_r 15.409 -
735_gem5_r 14.174 1.16%
736_ocio_r 16.240 -
737_gmsh_r 13.214 -
748_flightdm_r 8.918 -
750_sealcrypto_r 18.508 -
753_ns3_r 10.900 -
766_femflow_r 12.908 -
Geometric Mean 14.484 -