-
Notifications
You must be signed in to change notification settings - Fork 421
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
microoptimization on rand(::AliasTable) #1831
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1831 +/- ##
==========================================
- Coverage 85.94% 85.94% -0.01%
==========================================
Files 144 144
Lines 8658 8656 -2
==========================================
- Hits 7441 7439 -2
Misses 1217 1217 ☔ View full report in Codecov by Sentry. |
From the docs of In some cases, using `ifelse` instead of an `if` statement can eliminate the branch in generated code and provide higher performance in tight loops. Maybe something along these lines is the reason for the performance improvements? Did you compare the output of |
It looks like the |
I did try with however, I don't know if that result is cpu-specific or not though. is it possible |
That seems plausible to me. I imagine the CPU is able to eliminate the cost of bounds checking whilst benchmarking due to branch prediction. |
makes sense. happy to add back in the anything else needed? I can do more careful benchmarking across a range of inputs, but tbh this seems like a pretty quick win |
IMO we should only use |
that's true --- personally I don't mind omitting the |
It would definitely be less likely to run into BoundsErrors, but even with an inner constructor you are allowed to |
makes sense to me --- so this PR then improves safety as well as performance! |
Co-authored-by: David Widmann <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
cool, I had thought that @inbounds would improve performance, but maybe not significantly. Seems I should close JuliaStats/StatsBase.jl#630 then? |
doesn't necessary improve all the CI benchmarks, but I think those are kind of artificial. on all of my actual use cases I've tried, it's faster to use an
ifelse
and omit the@inbounds
status quo:
PR: