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 }})

FedericoStra

Addresses #115874.

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

@rustbot

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 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

This was referenced

Sep 17, 2023

FedericoStra

vacuus

tspiteri

@joshtriplett

@the8472

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

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

Looks great. Thanks.

@bors r+ rollup

@bors

📌 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

bors added a commit to rust-lang-ci/rust that referenced this pull request

Apr 22, 2024

@bors

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

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

@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

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

@bors

…llaumeGomez

Rollup of 7 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

bors added a commit to rust-lang-ci/rust that referenced this pull request

Apr 23, 2024

@bors

…llaumeGomez

Rollup of 7 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

rust-timer added a commit to rust-lang-ci/rust that referenced this pull request

Apr 23, 2024

@rust-timer

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

@matthiaskrgr

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

@matthiaskrgr

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

@matthiaskrgr

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

@fmease

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

@bors

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

@bors

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

@bors

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

@bors

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

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.