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

Optimize Symbol::integer by utilizing in-place formatting #122102

Merged
merged 1 commit into from
Mar 9, 2024

Conversation

Urgau
Copy link
Member

@Urgau Urgau commented Mar 6, 2024

This PR optimize Symbol::integer by utilizing itoa in-place formatting instead of going through a dynamically allocated String and the format machinery.

For some context: I was profiling rustc --check-cfg with callgrind and due to the way we currently setup all the targets and we end-up calling Symbol::integer multiple times for all the targets. Using itoa reduced the number of instructions.

@rustbot
Copy link
Collaborator

rustbot commented Mar 6, 2024

r? @fmease

rustbot has assigned @fmease.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 6, 2024
@rustbot
Copy link
Collaborator

rustbot commented Mar 6, 2024

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@compiler-errors
Copy link
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 6, 2024
@bors
Copy link
Contributor

bors commented Mar 6, 2024

⌛ Trying commit 33ef4b9 with merge 379d309...

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 6, 2024
Optimize `Symbol::integer` by utilizing in-place formatting

This PR optimize `Symbol::integer` by utilizing `itoa` in-place formatting instead of going through a dynamically allocated `String` and the format machinery.

<details>

For some context: I was profiling `rustc --check-cfg` with callgrind and due to the way we currently setup all the targets and we end-up calling `Symbol::integer` multiple times for all the targets. Using `itoa` reduced the number of instructions.

</details>
@bors
Copy link
Contributor

bors commented Mar 6, 2024

☀️ Try build successful - checks-actions
Build commit: 379d309 (379d3099f608108cc97bae4c5445ba5fea032a40)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (379d309): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

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

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)
6.3% [6.3%, 6.3%] 1
Regressions ❌
(secondary)
2.9% [2.9%, 2.9%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 6.3% [6.3%, 6.3%] 1

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)
5.9% [5.9%, 5.9%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 644.65s -> 646.027s (0.21%)
Artifact size: 175.06 MiB -> 175.07 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 7, 2024
@@ -2325,13 +2325,15 @@ pub mod sym {
///
/// The first few non-negative integers each have a static symbol and therefore
/// are fast.
pub fn integer<N: TryInto<usize> + Copy + ToString>(n: N) -> Symbol {
pub fn integer<N: TryInto<usize> + Copy + itoa::Integer>(n: N) -> Symbol {
if let Result::Ok(idx) = n.try_into() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to the PR, but why does this use Result::Ok instead of just Ok? D:

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea. The original commit even had Option::Some 😅.

@cjgillot
Copy link
Contributor

cjgillot commented Mar 8, 2024

Perf shows no distinguishable improvement, but it never hurts to remove useless work.
@bors r+

@cjgillot
Copy link
Contributor

cjgillot commented Mar 8, 2024

@bors r=

@bors
Copy link
Contributor

bors commented Mar 8, 2024

📌 Commit 33ef4b9 has been approved by ``

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 Mar 8, 2024
@cjgillot
Copy link
Contributor

cjgillot commented Mar 8, 2024

I need to type more slowly.
@bors r=cjgillot

@bors
Copy link
Contributor

bors commented Mar 8, 2024

📌 Commit 33ef4b9 has been approved by cjgillot

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Mar 9, 2024

⌛ Testing commit 33ef4b9 with merge 9d272a1...

@bors
Copy link
Contributor

bors commented Mar 9, 2024

☀️ Test successful - checks-actions
Approved by: cjgillot
Pushing 9d272a1 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 9, 2024
@bors bors merged commit 9d272a1 into rust-lang:master Mar 9, 2024
12 checks passed
@rustbot rustbot added this to the 1.78.0 milestone Mar 9, 2024
@Urgau Urgau deleted the optimize-symbol-integer branch March 9, 2024 11:22
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (9d272a1): comparison URL.

Overall result: ❌✅ regressions and improvements - 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)
0.3% [0.3%, 0.3%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.2% [-0.2%, -0.2%] 1
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
Regressions ❌
(secondary)
3.8% [2.4%, 5.3%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

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)
2.5% [2.4%, 2.7%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 650.646s -> 649.534s (-0.17%)
Artifact size: 172.57 MiB -> 172.59 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-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants