Skip to content

Commit 2b6ef17

Browse files
committed
Small performace optimizations
1 parent 2ec7990 commit 2b6ef17

File tree

3 files changed

+41
-22
lines changed

3 files changed

+41
-22
lines changed

doc/new_release.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
11
- update version in `phmap_config.h`
22
- update version in `CITATION.cff`
33
- update version in comment on top of `CMakeLists.txt`
4+
- update all versions # in `doc/new_release.md`.
45
- git commit
56
- git push
67
- create the new release on github (tag `v2.0.0` - use semantic versioning)
7-
- download the tar.gz from github, and use `sha256sum parallel-hashmap-1.4.0.tar.gz` on linux to get the sha256
8+
- download the tar.gz from github, and use `sha256sum parallel-hashmap-2.0.0.tar.gz` on linux to get the sha256
89

910
## conan
1011

1112
- use [forked repo](https://github.com/greg7mdp/conan-center-index)
1213
- sync fork in github
1314
- git checkout conan-io:master
14-
- git checkout -b phmap_1.4.0
15+
- git checkout -b phmap_2.0.0
1516
- update: `recipes/parallel-hashmap/all/conandata.yml` and `recipes/parallel-hashmap/config.yml`
1617
- sudo pip install conan -U
1718
- cd recipes/parallel-hashmap/all
18-
- *does not work* conan create conanfile.py parallel-hashmap/1.4.0@ -pr:b=default -pr:h=default
19-
update version in `recipes/parallel-hashmap/all/conanfile.py`
19+
- *does not work* conan create conanfile.py parallel-hashmap/2.0.0@ -pr:b=default -pr:h=default
20+
*no version??* update version in `recipes/parallel-hashmap/all/conanfile.py`
2021
- git diff
21-
- git commit -am "[parallel-hashmap] Bump version to 1.4.0"
22-
- git push origin phmap_1.4.0
22+
- git commit -am "[parallel-hashmap] Bump version to 2.0.0"
23+
- git push origin phmap_2.0.0
2324
- create PR like [this](https://github.com/conan-io/conan-center-index/pull/13161)
2425

2526

2627
## vcpkg
2728

2829
- use [forked repo](https://github.com/greg7mdp/vcpkg)
2930
- sync fork in github
30-
- git checkout -b phmap_1.4.0
31-
- update ports/gtl/portfile.cmake (the sha512) and ports/gtl/vcpkg.json
31+
- `git checkout -b phmap_2.0.0`
32+
- update ports/parallel-hashmap/portfile.cmake (the sha512) and ports/parallel-hashmap/vcpkg.json (the version #)
3233
- commit
33-
- vcpkg x-add-version --all --overwrite-version ## (or ./vcpkg.exe --no-dry-run upgrade )
34+
- `./bootstrap-vcpkg.sh`
35+
- `vcpkg x-add-version --all --overwrite-version` ## (or `./vcpkg.exe --no-dry-run upgrade` )
3436
- commit
3537
- push
3638
- create PR

parallel_hashmap/phmap.h

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ inline bool IsValidCapacity(size_t n) { return ((n + 1) & n) == 0 && n > 0; }
555555
// FULL -> DELETED
556556
// --------------------------------------------------------------------------
557557
inline void ConvertDeletedToEmptyAndFullToDeleted(
558-
ctrl_t* ctrl, size_t capacity)
558+
ctrl_t* PHMAP_RESTRICT ctrl, size_t capacity)
559559
{
560560
assert(ctrl[capacity] == kSentinel);
561561
assert(IsValidCapacity(capacity));
@@ -1857,20 +1857,22 @@ class raw_hash_set
18571857
friend struct phmap::priv::hashtable_debug_internal::HashtableDebugAccess;
18581858

18591859
template <class K = key_type>
1860-
bool find_impl(const key_arg<K>& key, size_t hashval, size_t& offset) {
1860+
bool find_impl(const key_arg<K>& PHMAP_RESTRICT key, size_t hashval, size_t& PHMAP_RESTRICT offset) {
1861+
auto ctrl_ptr = ctrl_;
18611862
PHMAP_IF_CONSTEXPR (!std_alloc_t::value) {
18621863
// ctrl_ could be nullptr
1863-
if (!ctrl_)
1864+
if (!ctrl_ptr)
18641865
return false;
18651866
}
18661867
auto seq = probe(hashval);
1868+
auto slots_ptr = slots_;
18671869
while (true) {
1868-
Group g{ ctrl_ + seq.offset() };
1870+
Group g{ ctrl_ptr + seq.offset() };
18691871
for (uint32_t i : g.Match((h2_t)H2(hashval))) {
18701872
offset = seq.offset((size_t)i);
18711873
if (PHMAP_PREDICT_TRUE(PolicyTraits::apply(
18721874
EqualElement<K>{key, eq_ref()},
1873-
PolicyTraits::element(slots_ + offset))))
1875+
PolicyTraits::element(slots_ptr + offset))))
18741876
return true;
18751877
}
18761878
if (PHMAP_PREDICT_TRUE(g.MatchEmpty()))
@@ -2034,9 +2036,11 @@ class raw_hash_set
20342036
std::is_same<typename Policy::is_flat, std::false_type>::value)) {
20352037
// node map, or not trivially destructible... we need to iterate and destroy values one by one
20362038
// std::cout << "either this is a node map or " << type_name<typename PolicyTraits::value_type>() << " is not trivially_destructible\n";
2037-
for (size_t i = 0; i != capacity_; ++i) {
2038-
if (IsFull(ctrl_[i])) {
2039-
PolicyTraits::destroy(&alloc_ref(), slots_ + i);
2039+
auto slots_ptr = slots_;
2040+
auto ctrl_ptr = ctrl_;
2041+
for (size_t i = 0, cnt = capacity_; i != cnt; ++i) {
2042+
if (IsFull(ctrl_ptr[i])) {
2043+
PolicyTraits::destroy(&alloc_ref(), slots_ptr + i);
20402044
}
20412045
}
20422046
}
@@ -2153,7 +2157,7 @@ class raw_hash_set
21532157
}
21542158
}
21552159

2156-
bool has_element(const value_type& elem, size_t hashval) const {
2160+
bool has_element(const value_type& PHMAP_RESTRICT elem, size_t hashval) const {
21572161
PHMAP_IF_CONSTEXPR (!std_alloc_t::value) {
21582162
// ctrl_ could be nullptr
21592163
if (!ctrl_)
@@ -2220,19 +2224,21 @@ class raw_hash_set
22202224

22212225
protected:
22222226
template <class K>
2223-
size_t _find_key(const K& key, size_t hashval) {
2227+
size_t _find_key(const K& PHMAP_RESTRICT key, size_t hashval) {
2228+
auto ctrl_ptr = ctrl_;
22242229
PHMAP_IF_CONSTEXPR (!std_alloc_t::value) {
22252230
// ctrl_ could be nullptr
2226-
if (!ctrl_)
2231+
if (!ctrl_ptr)
22272232
return (size_t)-1;
22282233
}
22292234
auto seq = probe(hashval);
2235+
auto slots_ptr = slots_;
22302236
while (true) {
2231-
Group g{ctrl_ + seq.offset()};
2237+
Group g{ctrl_ptr + seq.offset()};
22322238
for (uint32_t i : g.Match((h2_t)H2(hashval))) {
22332239
if (PHMAP_PREDICT_TRUE(PolicyTraits::apply(
22342240
EqualElement<K>{key, eq_ref()},
2235-
PolicyTraits::element(slots_ + seq.offset((size_t)i)))))
2241+
PolicyTraits::element(slots_ptr + seq.offset((size_t)i)))))
22362242
return seq.offset((size_t)i);
22372243
}
22382244
if (PHMAP_PREDICT_TRUE(g.MatchEmpty())) break;

parallel_hashmap/phmap_config.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,17 @@
661661
#define PHMAP_BUILTIN_UNREACHABLE() (void)0
662662
#endif
663663

664+
// ----------------------------------------------------------------------
665+
// RESTRICT
666+
// ----------------------------------------------------------------------
667+
#if (defined(__GNUC__) && (__GNUC__ > 3)) || defined(__clang__)
668+
#define PHMAP_RESTRICT __restrict__
669+
#elif defined(_MSC_VER) && _MSC_VER >= 1400
670+
#define PHMAP_RESTRICT __restrict
671+
#else
672+
#define PHMAP_RESTRICT
673+
#endif
674+
664675
// ----------------------------------------------------------------------
665676
// base/macros.h
666677
// ----------------------------------------------------------------------

0 commit comments

Comments
 (0)