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

checked_ilog: improve performance #115913

Merged
merged 5 commits into from
Apr 23, 2024
Merged

Conversation

FedericoStra
Copy link
Contributor

Addresses #115874.

(This PR replicates the original #115875, which I accidentally closed by deleting my forked repository...)

@rustbot
Copy link
Collaborator

rustbot commented Sep 17, 2023

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 rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Sep 17, 2023
@FedericoStra FedericoStra force-pushed the checked_ilog branch 2 times, most recently from b1a392a to 00035b5 Compare September 17, 2023 13:54
@joshtriplett
Copy link
Member

r? libs

@rustbot rustbot assigned cuviper and unassigned joshtriplett Feb 11, 2024
@the8472 the8472 assigned the8472 and unassigned cuviper Feb 21, 2024
@the8472
Copy link
Member

the8472 commented Feb 29, 2024

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 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 Feb 29, 2024
@tspiteri
Copy link
Contributor

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

@the8472
Copy link
Member

the8472 commented Apr 21, 2024

Looks great. Thanks.

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Apr 21, 2024

📌 Commit 3de51c9 has been approved by the8472

It is now in the queue for this repository.

@bors 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 Apr 21, 2024
@bors
Copy link
Contributor

bors commented Apr 22, 2024

⌛ Testing commit 3de51c9 with merge 981835d...

bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 22, 2024
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...)
@rust-log-analyzer
Copy link
Collaborator

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
Copy link
Contributor

bors commented Apr 22, 2024

💔 Test failed - checks-actions

@bors 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 Apr 22, 2024
@the8472
Copy link
Member

the8472 commented Apr 22, 2024

Looks like a flaky test in miri, other PRs have run into that too.

@bors retry

@bors 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 Apr 22, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 22, 2024
…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 Apr 23, 2024
…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 bors merged commit 206e0df into rust-lang:master Apr 23, 2024
11 of 12 checks passed
@rustbot rustbot added this to the 1.79.0 milestone Apr 23, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 23, 2024
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 Jun 1, 2024
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 Jun 1, 2024
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 Jun 1, 2024
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 Jun 1, 2024
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 Jun 2, 2024
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 Jun 5, 2024
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 Jun 20, 2024
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 Jun 28, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants