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

Remove bounds checks #143

Merged
merged 2 commits into from
Nov 3, 2023
Merged

Conversation

mhr3
Copy link
Contributor

@mhr3 mhr3 commented Oct 29, 2023

This branch removes some bounds checks from the for loops, which speeds up bunch of operations. I've mostly focused on the in-place methods, given the overhead of the allocations and data copies in the other methods is quite large. Also tbh I'm not really sure why does go sometimes require the slice to be a separate variable and sometimes not, but I can confirm every one of these changes is necessary to remove the bounds checks.

Here's a benchstat comparison of this branch vs master:

name                                    old time/op  new time/op  delta
BitsetOps/Equal-8                       1.08µs ± 1%  0.67µs ± 2%  -37.56%  (p=0.000 n=9+9)
BitsetOps/FlipRange-8                    700ns ± 2%   649ns ± 2%   -7.38%  (p=0.000 n=10+8)
BitsetOps/NextSet-8                      722ns ± 3%   471ns ± 0%  -34.74%  (p=0.000 n=10+9)
BitsetOps/NextClear-8                    962ns ± 3%   473ns ± 3%  -50.80%  (p=0.000 n=9+9)
BitsetOps/DifferenceCardinality-8        673ns ± 2%   656ns ± 1%   -2.51%  (p=0.000 n=10+10)
BitsetOps/InPlaceDifference-8           1.02µs ± 2%  0.51µs ± 2%  -49.76%  (p=0.000 n=10+10)
BitsetOps/InPlaceUnion-8                1.01µs ± 2%  0.51µs ± 3%  -49.38%  (p=0.000 n=10+10)
BitsetOps/InPlaceIntersection-8         1.03µs ± 2%  0.52µs ± 0%  -49.52%  (p=0.000 n=10+9)
BitsetOps/InPlaceSymmetricDifference-8  1.03µs ± 2%  0.52µs ± 0%  -49.98%  (p=0.000 n=10+10)

bitset.go Show resolved Hide resolved
if wn <= 0 {
return true
}
_ = b.set[wn-1]
Copy link
Member

Choose a reason for hiding this comment

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

Can we fuse those in one line?

_, _ = b.set[wn-1], c.set[wn-1]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't checked the output of check_bce, but yeah, should be fine.

@lemire
Copy link
Member

lemire commented Nov 1, 2023

@mhr3 That's a fantastic PR and we will merge it. Can you have a look at my two comments? These are not requests for you to change your code, but I'd like you to react to my comments.

@lemire lemire merged commit aaffecb into bits-and-blooms:master Nov 3, 2023
15 checks passed
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.

2 participants