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

Add Benchmarks for int_pow Methods. #119430

Merged
merged 4 commits into from
Jan 12, 2024
Merged

Conversation

NCGThompson
Copy link
Contributor

@NCGThompson NCGThompson commented Dec 30, 2023

There is quite a bit of room for improvement in performance of the int_pow family of methods. I added benchmarks for those functions. In particular, there are benchmarks for small compile-time bases to measure the effect of #114390. I added a lot (245), but all but 22 of them are marked with #[ignore]. There are a lot of macros, and I would appreciate feedback on how to simplify them.

To run benches relevant to #114390, use ./x bench core --stage 1 -- pow_base_const --include-ignored.

@rustbot
Copy link
Collaborator

rustbot commented Dec 30, 2023

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @cuviper (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 Dec 30, 2023
@NCGThompson
Copy link
Contributor Author

Surprisingly, at least on Aarch64, checked pow unwrapped is very slightly faster than wrapping pow, while checked pow unwrapped unchecked is among the slowest. I guessed the assume statement produced from the unwrap unchecked seems to be helping more than it is hurting. I found a way to unwrap it without generating an assume statement.

*option.as_slice().as_ptr().cast::<$t>()

When I benched it though, and it was significantly slower than the unwrap uncheck.

On Aarch64 but not x86_64, overflowing i128 is dramatically (~5x) slower than overflowing u128. This is because on Aarch64, signed overflowing multiply does a compuler-rt function call while unsigned overflowing multiply is inlined. I'll have to check what happens on other architectures with Compiler Explorer. To work around this, we can take advantage of the fact that any integer to an even power is non-negative. I've already wrote a similar algorithm in Rust before.

@NCGThompson
Copy link
Contributor Author

./x fmt is the reason some pow_bench_template! calls are a single line and others have the arguments listed vertically. I know it is inconsistent. Should I leave it the way ./x fmt likes it or should I somehow override it?

@NCGThompson
Copy link
Contributor Author

@cuviper Updated based on your feedback. I also rebased and force-pushed it.

@cuviper
Copy link
Member

cuviper commented Jan 11, 2024

Looks good, thanks!

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jan 11, 2024

📌 Commit c65c35b has been approved by cuviper

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-review Status: Awaiting review from the assignee but also interested parties. labels Jan 11, 2024
@bors
Copy link
Contributor

bors commented Jan 11, 2024

⌛ Testing commit c65c35b with merge 752baf0...

bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 11, 2024
Add Benchmarks for int_pow Methods.

There is quite a bit of room for improvement in performance of the `int_pow` family of methods. I added benchmarks for those functions. In particular, there are benchmarks for small compile-time bases to measure the effect of  rust-lang#114390. ~~I added a lot (245), but all but 22 of them are marked with `#[ignore]`. There are a lot of macros, and I would appreciate feedback on how to simplify them.~~

~~To run benches relevant to rust-lang#114390, use `./x bench core --stage 1 -- pow_base_const --include-ignored`.~~
@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[RUSTC-TIMING] process_spawning test:true 1.399
[RUSTC-TIMING] env test:true 1.565
[RUSTC-TIMING] stdbenches test:true 2.936
[RUSTC-TIMING] test test:true 15.804
##[error]The runner has received a shutdown signal. This can happen when the runner service is stopped, or a manually started runner is canceled.
##[group]Clock drift check
  local time: Fri Jan 12 00:02:09 UTC 2024
  local time: Fri Jan 12 00:02:09 UTC 2024
Session terminated, killing shell... ...killed.
##[error]The operation was canceled.
Cleaning up orphan processes

@bors
Copy link
Contributor

bors commented Jan 12, 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 Jan 12, 2024
@cuviper
Copy link
Member

cuviper commented Jan 12, 2024

@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 Jan 12, 2024
@NCGThompson
Copy link
Contributor Author

@bors retry

Is this definitely a random error, or could it have anything to do with my changes? If I interpreted the logs correctly, it was the drift test that failed, and that seems unrelated to the changes.

@cuviper
Copy link
Member

cuviper commented Jan 12, 2024

This message comes up occasionally on that particular runner, unrelated to any PR changes:

##[error]The runner has received a shutdown signal. This can happen when the runner service is stopped, or a manually started runner is canceled.

@bors
Copy link
Contributor

bors commented Jan 12, 2024

⌛ Testing commit c65c35b with merge 6029085...

@NCGThompson
Copy link
Contributor Author

@cuviper Is there a way to run or view the results of the library benchmarks on all the platforms that the CI tests?

@bors
Copy link
Contributor

bors commented Jan 12, 2024

☀️ Test successful - checks-actions
Approved by: cuviper
Pushing 6029085 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jan 12, 2024
@bors bors merged commit 6029085 into rust-lang:master Jan 12, 2024
12 checks passed
@rustbot rustbot added this to the 1.77.0 milestone Jan 12, 2024
@cuviper
Copy link
Member

cuviper commented Jan 12, 2024

Most of the targets are cross-compiled in CI, and AFAIK we don't even run those benchmarks on native targets in CI. They're really only useful for developers to run.

For more holistic benchmarking, see https://perf.rust-lang.org/ (source /~https://github.com/rust-lang/rustc-perf)

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (6029085): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.9% [1.9%, 1.9%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.9% [0.6%, 1.2%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.5% [-4.0%, -3.1%] 2
All ❌✅ (primary) 0.9% [0.6%, 1.2%] 2

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.3% [-3.1%, -0.4%] 5
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.3% [-3.1%, -0.4%] 5

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 666.002s -> 666.091s (0.01%)
Artifact size: 308.40 MiB -> 308.42 MiB (0.01%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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.

6 participants