checked_ilog: improve performance by FedericoStra · Pull Request #115913 · rust-lang/rust (original) (raw)
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 andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation17 Commits5 Checks0 Files changed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
Addresses #115874.
(This PR replicates the original #115875, which I accidentally closed by deleting my forked repository...)
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @joshtriplett (or someone else) soon.
Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review
and S-waiting-on-author
) stays updated, invoking these commands when appropriate:
@rustbot author
: the review is finished, PR author should check the comments and take action accordingly@rustbot review
: the author is ready for a review, this PR will be queued again in the reviewer's queue
rustbot added S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
Relevant to the library team, which will review and decide on the PR/issue.
labels
This was referenced
Sep 17, 2023
The implementation looks correct and we do have exhaustive tests for u16 so that part should be fine. And multiplication should be quite obviously better than division. But since you added benchmark sanyway can you add the before/after benchmark results to PR comment for future reference?
the8472 added S-waiting-on-author
Status: This is awaiting some action (such as code changes or more information) from the author.
and removed S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
labels
I ran the benchmarks included in the fourth commit. Basically, for "before" I cherry picked just the fourth commit onto the master branch, and for the "after" I rebased the whole PR onto the master. Results below:
Before:
num::int_log::u128_log_geometric 82.91µs/iter +/- 1.20µs
num::int_log::u128_log_random 2.10ms/iter +/- 2.74µs
num::int_log::u128_log_random_small 1.42ms/iter +/- 14.30µs
num::int_log::u16_log_geometric 740.00ns/iter +/- 0.00ns
num::int_log::u16_log_random 634.11µs/iter +/- 10.48µs
num::int_log::u16_log_random_small 502.78µs/iter +/- 3.06µs
num::int_log::u32_log_geometric 4.29µs/iter +/- 11.00ns
num::int_log::u32_log_random 757.75µs/iter +/- 2.19µs
num::int_log::u32_log_random_small 203.69µs/iter +/- 2.36µs
num::int_log::u64_log_geometric 26.20µs/iter +/- 124.00ns
num::int_log::u64_log_random 1.09ms/iter +/- 3.65µs
num::int_log::u64_log_random_small 251.95µs/iter +/- 3.23µs
num::int_log::u8_log_geometric 180.00ns/iter +/- 6.00ns
num::int_log::u8_log_random 192.59µs/iter +/- 2.61µs
num::int_log::u8_log_random_small 192.83µs/iter +/- 2.88µs
After:
num::int_log::u128_log_geometric 26.60µs/iter +/- 65.00ns
num::int_log::u128_log_random 1.83ms/iter +/- 11.76µs
num::int_log::u128_log_random_small 936.31µs/iter +/- 3.43µs
num::int_log::u16_log_geometric 296.00ns/iter +/- 17.00ns
num::int_log::u16_log_random 466.24µs/iter +/- 2.04µs
num::int_log::u16_log_random_small 407.55µs/iter +/- 9.85µs
num::int_log::u32_log_geometric 812.00ns/iter +/- 6.00ns
num::int_log::u32_log_random 451.27µs/iter +/- 2.17µs
num::int_log::u32_log_random_small 468.65µs/iter +/- 2.36µs
num::int_log::u64_log_geometric 4.99µs/iter +/- 30.00ns
num::int_log::u64_log_random 593.27µs/iter +/- 1.83µs
num::int_log::u64_log_random_small 179.98µs/iter +/- 3.62µs
num::int_log::u8_log_geometric 129.00ns/iter +/- 3.00ns
num::int_log::u8_log_random 475.02µs/iter +/- 1.58µs
num::int_log::u8_log_random_small 474.46µs/iter +/- 1.39µs
Looks great. Thanks.
@bors r+ rollup
📌 Commit 3de51c9 has been approved by the8472
It is now in the queue for this repository.
bors added S-waiting-on-bors
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
and removed S-waiting-on-author
Status: This is awaiting some action (such as code changes or more information) from the author.
labels
bors added a commit to rust-lang-ci/rust that referenced this pull request
checked_ilog: improve performance
Addresses rust-lang#115874.
(This PR replicates the original rust-lang#115875, which I accidentally closed by deleting my forked repository...)
The job x86_64-gnu-aux
failed! Check out the build log: (web) (plain)
Click to see the possible cause of the failure (guessed by this bot)
bors added S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
and removed S-waiting-on-bors
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
labels
Looks like a flaky test in miri, other PRs have run into that too.
@bors retry
bors added S-waiting-on-bors
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
and removed S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
labels
bors added a commit to rust-lang-ci/rust that referenced this pull request
…llaumeGomez
Rollup of 7 pull requests
Successful merges:
- rust-lang#115913 (checked_ilog: improve performance)
- rust-lang#124178 ([cleanup] [llvm backend] Prevent creating the same
Instance::mono
multiple times) - rust-lang#124183 (Stop taking
ParamTy
/ParamConst
/EarlyParamRegion
/AliasTy
by ref) - rust-lang#124217 (coverage: Prepare for improved branch coverage)
- rust-lang#124230 (Stabilize generic
NonZero
.) - rust-lang#124252 (Improve ICE message for forbidden dep-graph reads.)
- rust-lang#124268 (Update books)
r? @ghost
@rustbot
modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request
…llaumeGomez
Rollup of 7 pull requests
Successful merges:
- rust-lang#115913 (checked_ilog: improve performance)
- rust-lang#124178 ([cleanup] [llvm backend] Prevent creating the same
Instance::mono
multiple times) - rust-lang#124183 (Stop taking
ParamTy
/ParamConst
/EarlyParamRegion
/AliasTy
by ref) - rust-lang#124217 (coverage: Prepare for improved branch coverage)
- rust-lang#124230 (Stabilize generic
NonZero
.) - rust-lang#124252 (Improve ICE message for forbidden dep-graph reads.)
- rust-lang#124268 (Update books)
r? @ghost
@rustbot
modify labels: rollup
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request
Rollup merge of rust-lang#115913 - FedericoStra:checked_ilog, r=the8472
checked_ilog: improve performance
Addresses rust-lang#115874.
(This PR replicates the original rust-lang#115875, which I accidentally closed by deleting my forked repository...)
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request
Unroll first iteration of checked_ilog loop
This follows the optimization of rust-lang#115913. As shown in rust-lang#115913 (comment), the performance was improved in all important cases, but some regressions were introduced for the benchmarks u32_log_random_small
, u8_log_random
and u8_log_random_small
.
Basically, rust-lang#115913 changed the implementation from one division per iteration to one multiplication per iteration plus one division. When there are zero iterations, this is a regression from zero divisions to one division.
This PR avoids this by avoiding the division if we need zero iterations by returning Some(0)
early. It also reduces the number of multiplications by one in all other cases.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request
Unroll first iteration of checked_ilog loop
This follows the optimization of rust-lang#115913. As shown in rust-lang#115913 (comment), the performance was improved in all important cases, but some regressions were introduced for the benchmarks u32_log_random_small
, u8_log_random
and u8_log_random_small
.
Basically, rust-lang#115913 changed the implementation from one division per iteration to one multiplication per iteration plus one division. When there are zero iterations, this is a regression from zero divisions to one division.
This PR avoids this by avoiding the division if we need zero iterations by returning Some(0)
early. It also reduces the number of multiplications by one in all other cases.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request
Unroll first iteration of checked_ilog loop
This follows the optimization of rust-lang#115913. As shown in rust-lang#115913 (comment), the performance was improved in all important cases, but some regressions were introduced for the benchmarks u32_log_random_small
, u8_log_random
and u8_log_random_small
.
Basically, rust-lang#115913 changed the implementation from one division per iteration to one multiplication per iteration plus one division. When there are zero iterations, this is a regression from zero divisions to one division.
This PR avoids this by avoiding the division if we need zero iterations by returning Some(0)
early. It also reduces the number of multiplications by one in all other cases.
fmease added a commit to fmease/rust that referenced this pull request
Unroll first iteration of checked_ilog loop
This follows the optimization of rust-lang#115913. As shown in rust-lang#115913 (comment), the performance was improved in all important cases, but some regressions were introduced for the benchmarks u32_log_random_small
, u8_log_random
and u8_log_random_small
.
Basically, rust-lang#115913 changed the implementation from one division per iteration to one multiplication per iteration plus one division. When there are zero iterations, this is a regression from zero divisions to one division.
This PR avoids this by avoiding the division if we need zero iterations by returning Some(0)
early. It also reduces the number of multiplications by one in all other cases.
bors added a commit to rust-lang-ci/rust that referenced this pull request
Unroll first iteration of checked_ilog loop
This follows the optimization of rust-lang#115913. As shown in rust-lang#115913 (comment), the performance was improved in all important cases, but some regressions were introduced for the benchmarks u32_log_random_small
, u8_log_random
and u8_log_random_small
.
Basically, rust-lang#115913 changed the implementation from one division per iteration to one multiplication per iteration plus one division. When there are zero iterations, this is a regression from zero divisions to one division.
This PR avoids this by avoiding the division if we need zero iterations by returning Some(0)
early. It also reduces the number of multiplications by one in all other cases.
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request
Unroll first iteration of checked_ilog loop
This follows the optimization of #115913. As shown in rust-lang/rust#115913 (comment), the performance was improved in all important cases, but some regressions were introduced for the benchmarks u32_log_random_small
, u8_log_random
and u8_log_random_small
.
Basically, #115913 changed the implementation from one division per iteration to one multiplication per iteration plus one division. When there are zero iterations, this is a regression from zero divisions to one division.
This PR avoids this by avoiding the division if we need zero iterations by returning Some(0)
early. It also reduces the number of multiplications by one in all other cases.
bors added a commit to rust-lang/rust-analyzer that referenced this pull request
Unroll first iteration of checked_ilog loop
This follows the optimization of #115913. As shown in rust-lang/rust#115913 (comment), the performance was improved in all important cases, but some regressions were introduced for the benchmarks u32_log_random_small
, u8_log_random
and u8_log_random_small
.
Basically, #115913 changed the implementation from one division per iteration to one multiplication per iteration plus one division. When there are zero iterations, this is a regression from zero divisions to one division.
This PR avoids this by avoiding the division if we need zero iterations by returning Some(0)
early. It also reduces the number of multiplications by one in all other cases.
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request
Unroll first iteration of checked_ilog loop
This follows the optimization of #115913. As shown in rust-lang/rust#115913 (comment), the performance was improved in all important cases, but some regressions were introduced for the benchmarks u32_log_random_small
, u8_log_random
and u8_log_random_small
.
Basically, #115913 changed the implementation from one division per iteration to one multiplication per iteration plus one division. When there are zero iterations, this is a regression from zero divisions to one division.
This PR avoids this by avoiding the division if we need zero iterations by returning Some(0)
early. It also reduces the number of multiplications by one in all other cases.
Labels
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Relevant to the library team, which will review and decide on the PR/issue.