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

z: use MemHashString and xxhash.Sum64String #153

Merged
merged 2 commits into from
May 12, 2020

Conversation

zchee
Copy link
Contributor

@zchee zchee commented Mar 29, 2020

Use MemHashString and xxhash.Sum64String for KeyToHash.

$ go test -v -run='^$' -bench=. -benchmem -count 10 ./... | tee {old,new}.txt
$ benchstat -geomean old.txt new.txt
name                old time/op    new time/op     delta
pkg:github.com/dgraph-io/ristretto goos:darwin goarch:amd64
SketchIncrement-16    10.4ns ± 6%      8.4ns ± 3%  -18.84%  (p=0.000 n=10+10)
SketchEstimate-16     11.7ns ± 6%      9.8ns ± 6%  -16.26%  (p=0.000 n=10+10)
StoreGet-16           66.3ns ± 8%     55.6ns ± 9%  -16.20%  (p=0.000 n=10+9)
StoreSet-16            307ns ± 3%      297ns ± 6%     ~     (p=0.062 n=9+10)
StoreUpdate-16         294ns ± 6%      281ns ±10%     ~     (p=0.101 n=10+10)
pkg:github.com/dgraph-io/ristretto/z goos:darwin goarch:amd64
M_New-16              17.1µs ± 4%     16.9µs ± 8%     ~     (p=0.971 n=10+10)
M_Clear-16            2.31µs ± 6%     2.06µs ± 7%  -10.65%  (p=0.000 n=10+10)
M_Add-16              1.96ms ± 2%     1.89ms ± 5%   -3.61%  (p=0.004 n=10+10)
M_Has-16              1.84ms ± 9%     1.81ms ± 8%     ~     (p=0.529 n=10+10)
MemHash-16            6.26ns ± 2%     6.25ns ± 8%     ~     (p=0.858 n=9+10)
MemHashString-16      10.3ns ± 2%     10.3ns ± 4%     ~     (p=0.661 n=10+10)
Sip-16                40.1ns ± 5%     38.5ns ± 6%   -4.04%  (p=0.016 n=10+10)
Farm-16               7.95ns ± 4%     7.28ns ± 6%   -8.37%  (p=0.000 n=10+9)
Fnv-16                54.1ns ± 2%     52.8ns ± 6%     ~     (p=0.106 n=8+10)
NanoTime-16           32.9ns ± 3%     31.8ns ± 4%   -3.50%  (p=0.003 n=9+10)
CPUTicks-16           10.7ns ± 6%     10.6ns ± 5%     ~     (p=0.421 n=10+10)
FastRand-16           0.50ns ±18%     0.47ns ±20%     ~     (p=0.271 n=10+10)
RandSource-16         1.34ns ±12%     1.29ns ±10%     ~     (p=0.322 n=9+10)
RandGlobal-16         84.0ns ± 6%     80.0ns ± 3%   -4.71%  (p=0.000 n=9+9)
RandAtomic-16         25.1ns ± 2%     23.2ns ± 5%   -7.65%  (p=0.000 n=10+10)

[Geo mean]             109ns           102ns        -6.04%

name                old speed      new speed       delta
pkg:github.com/dgraph-io/ristretto goos:darwin goarch:amd64
SketchIncrement-16  96.5MB/s ± 6%  118.8MB/s ± 3%  +23.12%  (p=0.000 n=10+10)
SketchEstimate-16   85.7MB/s ± 6%  102.5MB/s ± 6%  +19.58%  (p=0.000 n=10+10)
StoreGet-16         15.1MB/s ± 9%   17.7MB/s ±17%  +17.09%  (p=0.000 n=10+10)
StoreSet-16         3.26MB/s ± 3%   3.37MB/s ± 7%     ~     (p=0.083 n=9+10)
StoreUpdate-16      3.40MB/s ± 6%   3.58MB/s ±10%     ~     (p=0.109 n=10+10)
pkg:github.com/dgraph-io/ristretto/z goos:darwin goarch:amd64
MemHash-16          10.2GB/s ± 2%   10.3GB/s ± 8%     ~     (p=0.905 n=9+10)
MemHashString-16    11.9GB/s ± 2%   12.0GB/s ± 4%     ~     (p=0.739 n=10+10)

[Geo mean]           108MB/s         118MB/s        +9.51%

name                old alloc/op   new alloc/op    delta
pkg:github.com/dgraph-io/ristretto goos:darwin goarch:amd64
SketchIncrement-16     0.00B           0.00B          ~     (all equal)
SketchEstimate-16      0.00B           0.00B          ~     (all equal)
StoreGet-16            0.00B           0.00B          ~     (all equal)
StoreSet-16            80.0B ± 0%      80.0B ± 0%     ~     (all equal)
StoreUpdate-16         80.0B ± 0%      80.0B ± 0%     ~     (all equal)
pkg:github.com/dgraph-io/ristretto/z goos:darwin goarch:amd64
M_New-16               131kB ± 0%      131kB ± 0%     ~     (all equal)
M_Clear-16             0.00B           0.00B          ~     (all equal)
M_Add-16               0.00B           0.00B          ~     (all equal)
M_Has-16               0.00B           0.00B          ~     (all equal)
MemHash-16             0.00B           0.00B          ~     (all equal)
MemHashString-16       0.00B           0.00B          ~     (all equal)
Sip-16                 0.00B           0.00B          ~     (all equal)
Farm-16                0.00B           0.00B          ~     (all equal)
Fnv-16                 0.00B           0.00B          ~     (all equal)
NanoTime-16            0.00B           0.00B          ~     (all equal)
CPUTicks-16            0.00B           0.00B          ~     (all equal)
FastRand-16            0.00B           0.00B          ~     (all equal)
RandSource-16          0.00B           0.00B          ~     (all equal)
RandGlobal-16          0.00B           0.00B          ~     (all equal)
RandAtomic-16          0.00B           0.00B          ~     (all equal)

[Geo mean]              943B            943B        +0.00%

name                old allocs/op  new allocs/op   delta
pkg:github.com/dgraph-io/ristretto goos:darwin goarch:amd64
SketchIncrement-16      0.00            0.00          ~     (all equal)
SketchEstimate-16       0.00            0.00          ~     (all equal)
StoreGet-16             0.00            0.00          ~     (all equal)
StoreSet-16             1.00 ± 0%       1.00 ± 0%     ~     (all equal)
StoreUpdate-16          1.00 ± 0%       1.00 ± 0%     ~     (all equal)
pkg:github.com/dgraph-io/ristretto/z goos:darwin goarch:amd64
M_New-16                2.00 ± 0%       2.00 ± 0%     ~     (all equal)
M_Clear-16              0.00            0.00          ~     (all equal)
M_Add-16                0.00            0.00          ~     (all equal)
M_Has-16                0.00            0.00          ~     (all equal)
MemHash-16              0.00            0.00          ~     (all equal)
MemHashString-16        0.00            0.00          ~     (all equal)
Sip-16                  0.00            0.00          ~     (all equal)
Farm-16                 0.00            0.00          ~     (all equal)
Fnv-16                  0.00            0.00          ~     (all equal)
NanoTime-16             0.00            0.00          ~     (all equal)
CPUTicks-16             0.00            0.00          ~     (all equal)
FastRand-16             0.00            0.00          ~     (all equal)
RandSource-16           0.00            0.00          ~     (all equal)
RandGlobal-16           0.00            0.00          ~     (all equal)
RandAtomic-16           0.00            0.00          ~     (all equal)

[Geo mean]              1.26            1.26        +0.00%

This change is Reviewable

zchee added 2 commits March 29, 2020 23:54
$ go test -v -run='^$' -bench=. -benchmem -count 10 ./...
$ benchstat -geomean old.txt new.txt
name                old time/op    new time/op     delta
pkg:github.com/dgraph-io/ristretto goos:darwin goarch:amd64
SketchIncrement-16    10.4ns ± 6%      8.4ns ± 3%  -18.84%  (p=0.000 n=10+10)
SketchEstimate-16     11.7ns ± 6%      9.8ns ± 6%  -16.26%  (p=0.000 n=10+10)
StoreGet-16           66.3ns ± 8%     55.6ns ± 9%  -16.20%  (p=0.000 n=10+9)
StoreSet-16            307ns ± 3%      297ns ± 6%     ~     (p=0.062 n=9+10)
StoreUpdate-16         294ns ± 6%      281ns ±10%     ~     (p=0.101 n=10+10)
pkg:github.com/dgraph-io/ristretto/z goos:darwin goarch:amd64
M_New-16              17.1µs ± 4%     16.9µs ± 8%     ~     (p=0.971 n=10+10)
M_Clear-16            2.31µs ± 6%     2.06µs ± 7%  -10.65%  (p=0.000 n=10+10)
M_Add-16              1.96ms ± 2%     1.89ms ± 5%   -3.61%  (p=0.004 n=10+10)
M_Has-16              1.84ms ± 9%     1.81ms ± 8%     ~     (p=0.529 n=10+10)
MemHash-16            6.26ns ± 2%     6.25ns ± 8%     ~     (p=0.858 n=9+10)
MemHashString-16      10.3ns ± 2%     10.3ns ± 4%     ~     (p=0.661 n=10+10)
Sip-16                40.1ns ± 5%     38.5ns ± 6%   -4.04%  (p=0.016 n=10+10)
Farm-16               7.95ns ± 4%     7.28ns ± 6%   -8.37%  (p=0.000 n=10+9)
Fnv-16                54.1ns ± 2%     52.8ns ± 6%     ~     (p=0.106 n=8+10)
NanoTime-16           32.9ns ± 3%     31.8ns ± 4%   -3.50%  (p=0.003 n=9+10)
CPUTicks-16           10.7ns ± 6%     10.6ns ± 5%     ~     (p=0.421 n=10+10)
FastRand-16           0.50ns ±18%     0.47ns ±20%     ~     (p=0.271 n=10+10)
RandSource-16         1.34ns ±12%     1.29ns ±10%     ~     (p=0.322 n=9+10)
RandGlobal-16         84.0ns ± 6%     80.0ns ± 3%   -4.71%  (p=0.000 n=9+9)
RandAtomic-16         25.1ns ± 2%     23.2ns ± 5%   -7.65%  (p=0.000 n=10+10)

[Geo mean]             109ns           102ns        -6.04%

name                old speed      new speed       delta
pkg:github.com/dgraph-io/ristretto goos:darwin goarch:amd64
SketchIncrement-16  96.5MB/s ± 6%  118.8MB/s ± 3%  +23.12%  (p=0.000 n=10+10)
SketchEstimate-16   85.7MB/s ± 6%  102.5MB/s ± 6%  +19.58%  (p=0.000 n=10+10)
StoreGet-16         15.1MB/s ± 9%   17.7MB/s ±17%  +17.09%  (p=0.000 n=10+10)
StoreSet-16         3.26MB/s ± 3%   3.37MB/s ± 7%     ~     (p=0.083 n=9+10)
StoreUpdate-16      3.40MB/s ± 6%   3.58MB/s ±10%     ~     (p=0.109 n=10+10)
pkg:github.com/dgraph-io/ristretto/z goos:darwin goarch:amd64
MemHash-16          10.2GB/s ± 2%   10.3GB/s ± 8%     ~     (p=0.905 n=9+10)
MemHashString-16    11.9GB/s ± 2%   12.0GB/s ± 4%     ~     (p=0.739 n=10+10)

[Geo mean]           108MB/s         118MB/s        +9.51%

name                old alloc/op   new alloc/op    delta
pkg:github.com/dgraph-io/ristretto goos:darwin goarch:amd64
SketchIncrement-16     0.00B           0.00B          ~     (all equal)
SketchEstimate-16      0.00B           0.00B          ~     (all equal)
StoreGet-16            0.00B           0.00B          ~     (all equal)
StoreSet-16            80.0B ± 0%      80.0B ± 0%     ~     (all equal)
StoreUpdate-16         80.0B ± 0%      80.0B ± 0%     ~     (all equal)
pkg:github.com/dgraph-io/ristretto/z goos:darwin goarch:amd64
M_New-16               131kB ± 0%      131kB ± 0%     ~     (all equal)
M_Clear-16             0.00B           0.00B          ~     (all equal)
M_Add-16               0.00B           0.00B          ~     (all equal)
M_Has-16               0.00B           0.00B          ~     (all equal)
MemHash-16             0.00B           0.00B          ~     (all equal)
MemHashString-16       0.00B           0.00B          ~     (all equal)
Sip-16                 0.00B           0.00B          ~     (all equal)
Farm-16                0.00B           0.00B          ~     (all equal)
Fnv-16                 0.00B           0.00B          ~     (all equal)
NanoTime-16            0.00B           0.00B          ~     (all equal)
CPUTicks-16            0.00B           0.00B          ~     (all equal)
FastRand-16            0.00B           0.00B          ~     (all equal)
RandSource-16          0.00B           0.00B          ~     (all equal)
RandGlobal-16          0.00B           0.00B          ~     (all equal)
RandAtomic-16          0.00B           0.00B          ~     (all equal)

[Geo mean]              943B            943B        +0.00%

name                old allocs/op  new allocs/op   delta
pkg:github.com/dgraph-io/ristretto goos:darwin goarch:amd64
SketchIncrement-16      0.00            0.00          ~     (all equal)
SketchEstimate-16       0.00            0.00          ~     (all equal)
StoreGet-16             0.00            0.00          ~     (all equal)
StoreSet-16             1.00 ± 0%       1.00 ± 0%     ~     (all equal)
StoreUpdate-16          1.00 ± 0%       1.00 ± 0%     ~     (all equal)
pkg:github.com/dgraph-io/ristretto/z goos:darwin goarch:amd64
M_New-16                2.00 ± 0%       2.00 ± 0%     ~     (all equal)
M_Clear-16              0.00            0.00          ~     (all equal)
M_Add-16                0.00            0.00          ~     (all equal)
M_Has-16                0.00            0.00          ~     (all equal)
MemHash-16              0.00            0.00          ~     (all equal)
MemHashString-16        0.00            0.00          ~     (all equal)
Sip-16                  0.00            0.00          ~     (all equal)
Farm-16                 0.00            0.00          ~     (all equal)
Fnv-16                  0.00            0.00          ~     (all equal)
NanoTime-16             0.00            0.00          ~     (all equal)
CPUTicks-16             0.00            0.00          ~     (all equal)
FastRand-16             0.00            0.00          ~     (all equal)
RandSource-16           0.00            0.00          ~     (all equal)
RandGlobal-16           0.00            0.00          ~     (all equal)
RandAtomic-16           0.00            0.00          ~     (all equal)

[Geo mean]              1.26            1.26        +0.00%
@CLAassistant
Copy link

CLAassistant commented Mar 29, 2020

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@martinmr martinmr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm: I'll get this approved by @manishrjain and merge it if he approves.

Reviewed 2 of 2 files at r1.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @jarifibrahim, @karlmcguire, and @manishrjain)

@zchee
Copy link
Contributor Author

zchee commented Apr 16, 2020

@jarifibrahim, @karlmcguire, @manishrjain
Sorry, ping.

@zchee
Copy link
Contributor Author

zchee commented Apr 20, 2020

@martinmr sorry, any progress?

Copy link
Contributor

@jarifibrahim jarifibrahim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zchee Apologies for the delay in review. This is a great improvement. I'll get it reviewed and merged today. Thank you for fixing it 🎉

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @jarifibrahim, @karlmcguire, and @manishrjain)

Copy link
Contributor

@manishrjain manishrjain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm: Sorry for the delay. This wasn't brought to my attention earlier. Thanks for your contribution, @zchee .

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @karlmcguire and @manishrjain)

@jarifibrahim jarifibrahim merged commit 7a3f2d3 into dgraph-io:master May 12, 2020
@jarifibrahim
Copy link
Contributor

@zchee Merged to master 🎉 💯

@erikdubbelboer erikdubbelboer mentioned this pull request Jun 15, 2020
jarifibrahim pushed a commit to dgraph-io/badger that referenced this pull request Jun 30, 2020
The update brings following changes from ristretto into badger

```
f66de99 Improve handling of updated items (dgraph-io/ristretto#168)
aec7994 Fix flaky TestCacheDel test (dgraph-io/ristretto#169)
a093fe6 Add benchmark plots to the project repo (dgraph-io/ristretto#166)
49dc42c Add Anurag as codeowner (dgraph-io/ristretto#158)
7a3f2d3 z: use MemHashString and xxhash.Sum64String (dgraph-io/ristretto#153)
9c31bb2 Check conflict key before updating expiration map. (dgraph-io/ristretto#154)
62cb731 Fix race condition in Cache.Clear (dgraph-io/ristretto#133)
9af1934 Docs and whitespace changes for readability. (dgraph-io/ristretto#143)
dbc185e Add changelog. (dgraph-io/ristretto#142)
ff325ad Remove key from policy after TTL eviction (dgraph-io/ristretto#130)
2dd5ff5 Use the require library in all the tests. (dgraph-io/ristretto#128)
7c48141 Use require in all tests in cache_test.go (dgraph-io/ristretto#127)
51e97ad Sets with TTL (dgraph-io/ristretto#122)
d3e7c37 Add benchmarks for math.rand and fastrand (dgraph-io/ristretto#118)
593823e Integrate fixes from PR dgraph-io/ristretto#91. (dgraph-io/ristretto#126)
29b4dd7 Fix comments. (dgraph-io/ristretto#123)
ddf345c Removed workflows directory. (dgraph-io/ristretto#124)
eb104d0 Add martinmr to CODEOWNERS file. (dgraph-io/ristretto#125)
```
jarifibrahim pushed a commit to dgraph-io/badger that referenced this pull request Jul 6, 2020
The update brings following changes from ristretto into badger

```
f66de99 Improve handling of updated items (dgraph-io/ristretto#168)
aec7994 Fix flaky TestCacheDel test (dgraph-io/ristretto#169)
a093fe6 Add benchmark plots to the project repo (dgraph-io/ristretto#166)
49dc42c Add Anurag as codeowner (dgraph-io/ristretto#158)
7a3f2d3 z: use MemHashString and xxhash.Sum64String (dgraph-io/ristretto#153)
9c31bb2 Check conflict key before updating expiration map. (dgraph-io/ristretto#154)
62cb731 Fix race condition in Cache.Clear (dgraph-io/ristretto#133)
9af1934 Docs and whitespace changes for readability. (dgraph-io/ristretto#143)
dbc185e Add changelog. (dgraph-io/ristretto#142)
ff325ad Remove key from policy after TTL eviction (dgraph-io/ristretto#130)
2dd5ff5 Use the require library in all the tests. (dgraph-io/ristretto#128)
7c48141 Use require in all tests in cache_test.go (dgraph-io/ristretto#127)
51e97ad Sets with TTL (dgraph-io/ristretto#122)
d3e7c37 Add benchmarks for math.rand and fastrand (dgraph-io/ristretto#118)
593823e Integrate fixes from PR dgraph-io/ristretto#91. (dgraph-io/ristretto#126)
29b4dd7 Fix comments. (dgraph-io/ristretto#123)
ddf345c Removed workflows directory. (dgraph-io/ristretto#124)
eb104d0 Add martinmr to CODEOWNERS file. (dgraph-io/ristretto#125)
```

(cherry picked from commit 09dfa66)
jarifibrahim pushed a commit to dgraph-io/badger that referenced this pull request Oct 2, 2020
The update brings following changes from ristretto into badger

```
f66de99 Improve handling of updated items (dgraph-io/ristretto#168)
aec7994 Fix flaky TestCacheDel test (dgraph-io/ristretto#169)
a093fe6 Add benchmark plots to the project repo (dgraph-io/ristretto#166)
49dc42c Add Anurag as codeowner (dgraph-io/ristretto#158)
7a3f2d3 z: use MemHashString and xxhash.Sum64String (dgraph-io/ristretto#153)
9c31bb2 Check conflict key before updating expiration map. (dgraph-io/ristretto#154)
62cb731 Fix race condition in Cache.Clear (dgraph-io/ristretto#133)
9af1934 Docs and whitespace changes for readability. (dgraph-io/ristretto#143)
dbc185e Add changelog. (dgraph-io/ristretto#142)
ff325ad Remove key from policy after TTL eviction (dgraph-io/ristretto#130)
2dd5ff5 Use the require library in all the tests. (dgraph-io/ristretto#128)
7c48141 Use require in all tests in cache_test.go (dgraph-io/ristretto#127)
51e97ad Sets with TTL (dgraph-io/ristretto#122)
d3e7c37 Add benchmarks for math.rand and fastrand (dgraph-io/ristretto#118)
593823e Integrate fixes from PR dgraph-io/ristretto#91. (dgraph-io/ristretto#126)
29b4dd7 Fix comments. (dgraph-io/ristretto#123)
ddf345c Removed workflows directory. (dgraph-io/ristretto#124)
eb104d0 Add martinmr to CODEOWNERS file. (dgraph-io/ristretto#125)
```
@zchee zchee deleted the z_memhash-string branch April 18, 2021 14:27
manishrjain pushed a commit to outcaste-io/outserv that referenced this pull request Jul 6, 2022
The update brings following changes from ristretto into badger

```
f66de99 Improve handling of updated items (dgraph-io/ristretto#168)
aec7994 Fix flaky TestCacheDel test (dgraph-io/ristretto#169)
a093fe6 Add benchmark plots to the project repo (dgraph-io/ristretto#166)
49dc42c Add Anurag as codeowner (dgraph-io/ristretto#158)
7a3f2d3 z: use MemHashString and xxhash.Sum64String (dgraph-io/ristretto#153)
9c31bb2 Check conflict key before updating expiration map. (dgraph-io/ristretto#154)
62cb731 Fix race condition in Cache.Clear (dgraph-io/ristretto#133)
9af1934 Docs and whitespace changes for readability. (dgraph-io/ristretto#143)
dbc185e Add changelog. (dgraph-io/ristretto#142)
ff325ad Remove key from policy after TTL eviction (dgraph-io/ristretto#130)
2dd5ff5 Use the require library in all the tests. (dgraph-io/ristretto#128)
7c48141 Use require in all tests in cache_test.go (dgraph-io/ristretto#127)
51e97ad Sets with TTL (dgraph-io/ristretto#122)
d3e7c37 Add benchmarks for math.rand and fastrand (dgraph-io/ristretto#118)
593823e Integrate fixes from PR dgraph-io/ristretto#91. (dgraph-io/ristretto#126)
29b4dd7 Fix comments. (dgraph-io/ristretto#123)
ddf345c Removed workflows directory. (dgraph-io/ristretto#124)
eb104d0 Add martinmr to CODEOWNERS file. (dgraph-io/ristretto#125)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants