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

perf: inline binary search #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

stevenh
Copy link

@stevenh stevenh commented Jul 6, 2024

Use inline version of binary search instead of sort.Search which is ~50% quicker in most cases.

benchstat -filter '.unit:ns/op' orig.log inline.log goos: linux
goarch: amd64
pkg: github.com/hashicorp/go-immutable-radix/v2
cpu: Intel(R) Core(TM) i9-14900HX
                                              │   orig.log    │             inline.log             │
                                              │    sec/op     │   sec/op     vs base               │
LongestPrefix/words-exact-match-early-32         59.47n ± 12%   29.70n ± 1%  -50.06% (p=0.002 n=6)
LongestPrefix/words-exact-match-late-32          56.99n ±  2%   33.43n ± 3%  -41.35% (p=0.002 n=6)
LongestPrefix/words-prefix-match-early-32       106.85n ±  3%   52.09n ± 2%  -51.24% (p=0.002 n=6)
LongestPrefix/words-prefix-match-late-32         75.12n ±  2%   38.78n ± 2%  -48.37% (p=0.002 n=6)
LongestPrefix/words-not-found-early-32          12.945n ±  2%   5.267n ± 3%  -59.31% (p=0.002 n=6)
LongestPrefix/words-not-found-late-32           12.415n ±  2%   4.577n ± 4%  -63.13% (p=0.002 n=6)
LongestPrefix/uuids-exact-match-early-32         61.14n ±  4%   33.76n ± 7%  -44.78% (p=0.002 n=6)
LongestPrefix/uuids-exact-match-late-32          60.79n ±  4%   35.28n ± 6%  -41.96% (p=0.002 n=6)
LongestPrefix/uuids-prefix-match-early-32        57.02n ±  8%   32.57n ± 4%  -42.87% (p=0.002 n=6)
LongestPrefix/uuids-prefix-match-late-32         58.01n ±  2%   34.44n ± 3%  -40.63% (p=0.002 n=6)
LongestPrefix/uuids-not-found-early-32           48.36n ±  3%   30.74n ± 3%  -36.44% (p=0.002 n=6)
LongestPrefix/uuids-not-found-late-32           11.600n ±  4%   4.099n ± 6%  -64.66% (p=0.002 n=6)
LongestPrefix/endpoints-exact-match-early-32     57.82n ±  4%   34.01n ± 3%  -41.18% (p=0.002 n=6)
LongestPrefix/endpoints-exact-match-late-32      73.75n ±  4%   41.46n ± 3%  -43.77% (p=0.002 n=6)
LongestPrefix/endpoints-prefix-match-early-32    51.55n ±  4%   30.58n ± 1%  -40.69% (p=0.002 n=6)
LongestPrefix/endpoints-prefix-match-late-32     63.00n ±  4%   40.37n ± 4%  -35.92% (p=0.002 n=6)
LongestPrefix/endpoints-not-found-early-32       6.098n ±  4%   2.606n ± 6%  -57.26% (p=0.002 n=6)
LongestPrefix/endpoints-not-found-late-32        6.188n ±  3%   2.646n ± 3%  -57.23% (p=0.002 n=6)
geomean                                          36.86n         18.93n       -48.63%

Use inline version of binary search instead of sort.Search which is
~50% quicker in most cases.

benchstat -filter '.unit:ns/op' orig.log inline.log
goos: linux
goarch: amd64
pkg: github.com/hashicorp/go-immutable-radix/v2
cpu: Intel(R) Core(TM) i9-14900HX
                                              │   orig.log    │             inline.log             │
                                              │    sec/op     │   sec/op     vs base               │
LongestPrefix/words-exact-match-early-32         59.47n ± 12%   29.70n ± 1%  -50.06% (p=0.002 n=6)
LongestPrefix/words-exact-match-late-32          56.99n ±  2%   33.43n ± 3%  -41.35% (p=0.002 n=6)
LongestPrefix/words-prefix-match-early-32       106.85n ±  3%   52.09n ± 2%  -51.24% (p=0.002 n=6)
LongestPrefix/words-prefix-match-late-32         75.12n ±  2%   38.78n ± 2%  -48.37% (p=0.002 n=6)
LongestPrefix/words-not-found-early-32          12.945n ±  2%   5.267n ± 3%  -59.31% (p=0.002 n=6)
LongestPrefix/words-not-found-late-32           12.415n ±  2%   4.577n ± 4%  -63.13% (p=0.002 n=6)
LongestPrefix/uuids-exact-match-early-32         61.14n ±  4%   33.76n ± 7%  -44.78% (p=0.002 n=6)
LongestPrefix/uuids-exact-match-late-32          60.79n ±  4%   35.28n ± 6%  -41.96% (p=0.002 n=6)
LongestPrefix/uuids-prefix-match-early-32        57.02n ±  8%   32.57n ± 4%  -42.87% (p=0.002 n=6)
LongestPrefix/uuids-prefix-match-late-32         58.01n ±  2%   34.44n ± 3%  -40.63% (p=0.002 n=6)
LongestPrefix/uuids-not-found-early-32           48.36n ±  3%   30.74n ± 3%  -36.44% (p=0.002 n=6)
LongestPrefix/uuids-not-found-late-32           11.600n ±  4%   4.099n ± 6%  -64.66% (p=0.002 n=6)
LongestPrefix/endpoints-exact-match-early-32     57.82n ±  4%   34.01n ± 3%  -41.18% (p=0.002 n=6)
LongestPrefix/endpoints-exact-match-late-32      73.75n ±  4%   41.46n ± 3%  -43.77% (p=0.002 n=6)
LongestPrefix/endpoints-prefix-match-early-32    51.55n ±  4%   30.58n ± 1%  -40.69% (p=0.002 n=6)
LongestPrefix/endpoints-prefix-match-late-32     63.00n ±  4%   40.37n ± 4%  -35.92% (p=0.002 n=6)
LongestPrefix/endpoints-not-found-early-32       6.098n ±  4%   2.606n ± 6%  -57.26% (p=0.002 n=6)
LongestPrefix/endpoints-not-found-late-32        6.188n ±  3%   2.646n ± 3%  -57.23% (p=0.002 n=6)
geomean                                          36.86n         18.93n       -48.63%
Copy link

hashicorp-cla-app bot commented Jul 6, 2024

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant