Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache hash code MSBs in Map buckets #31

Merged
merged 2 commits into from
Sep 7, 2021

Conversation

puzpuzpuz
Copy link
Owner

@puzpuzpuz puzpuzpuz commented Sep 6, 2021

Closes #2

  • Removes linked lists from Map buckets
    • Also increases bucket size to fit 7 entries (2 CLs). So, when compared with the current Map maximum number of entries in bucket decrease from 9 to 7 entries. On the other hand, spacial locality and data density improved
  • Adds a cache with top bytes of entry hash codes
    • Improves key lookup efficiency by caching one most significant byte of each map entry. This way string dereference and equality check is avoided for a significant portion of scanned entries
  • Decreases the shrink threshold fraction proportionally to the new map layout

Benchmark results

Here is the result of comparison with current main (v1.0.2) on my laptop (Ubuntu 20.04, i5-8300h, Go 1.17)

$ benchstat old.txt new.txt
name                      old time/op  new time/op  delta
Map_NoWarmUp/99%-reads-8  45.5ns ± 2%  33.5ns ± 0%  -26.31%  (p=0.008 n=5+5)
Map_NoWarmUp/90%-reads-8  59.0ns ± 3%  46.7ns ± 1%  -20.90%  (p=0.008 n=5+5)
Map_NoWarmUp/75%-reads-8  71.4ns ±23%  56.1ns ± 1%  -21.41%  (p=0.016 n=5+4)
Map_NoWarmUp/50%-reads-8  77.3ns ± 4%  77.2ns ±25%     ~     (p=0.690 n=5+5)
Map_NoWarmUp/0%-reads-8    102ns ±34%    94ns ±10%     ~     (p=1.000 n=5+5)
Map_WarmUp/100%-reads-8   64.4ns ± 0%  56.4ns ± 0%  -12.41%  (p=0.008 n=5+5)
Map_WarmUp/99%-reads-8    64.0ns ± 0%  55.8ns ± 0%  -12.77%  (p=0.008 n=5+5)
Map_WarmUp/90%-reads-8    64.7ns ± 0%  53.2ns ± 0%  -17.83%  (p=0.008 n=5+5)
Map_WarmUp/75%-reads-8    64.5ns ± 0%  53.0ns ± 0%  -17.92%  (p=0.029 n=4+4)
Map_WarmUp/50%-reads-8    68.2ns ± 9%  56.8ns ± 0%  -16.76%  (p=0.016 n=5+4)
Map_WarmUp/0%-reads-8     80.4ns ± 1%  69.3ns ± 1%  -13.79%  (p=0.016 n=5+4)

Also increases bucket size to fit 7 entries (2 CLs).
@puzpuzpuz puzpuzpuz added the enhancement New feature or request label Sep 6, 2021
@puzpuzpuz puzpuzpuz added this to the 1.1.0 milestone Sep 6, 2021
Improves key lookup efficiency by caching one most significant byte
of each map entry. This way string dereference and equality check
is avoided for a significant portion of scanned entries.
@puzpuzpuz puzpuzpuz force-pushed the enhancement/map-with-no-bucket-chaining branch from 80b2ff8 to d26bcfb Compare September 7, 2021 17:11
@codecov-commenter
Copy link

Codecov Report

Merging #31 (d26bcfb) into main (1fd9408) will decrease coverage by 1.98%.
The diff coverage is 94.73%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #31      +/-   ##
==========================================
- Coverage   96.66%   94.67%   -1.99%     
==========================================
  Files           5        5              
  Lines         509      488      -21     
==========================================
- Hits          492      462      -30     
- Misses         14       21       +7     
- Partials        3        5       +2     
Impacted Files Coverage Δ
map.go 93.00% <94.73%> (-2.88%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1fd9408...d26bcfb. Read the comment docs.

@puzpuzpuz puzpuzpuz merged commit 2fe4f89 into main Sep 7, 2021
@puzpuzpuz puzpuzpuz deleted the enhancement/map-with-no-bucket-chaining branch September 7, 2021 17:21
@puzpuzpuz puzpuzpuz changed the title Remove bucket chaining from Map Cache top hash code MSBs in Map buckets Sep 7, 2021
@puzpuzpuz puzpuzpuz changed the title Cache top hash code MSBs in Map buckets Cache hash code MSBs in Map buckets Dec 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider storing 6 bits of key hash codes in tagged pointers
2 participants