Skip to content

Streamline the format macro. #140188

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nnethercote
Copy link
Contributor

@nnethercote nnethercote commented Apr 23, 2025

Removing the unnecessary local variable speeds up compilation a little.

r? @cuviper

@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 Apr 23, 2025
@rust-log-analyzer

This comment has been minimized.

@nnethercote nnethercote force-pushed the streamline-format-macro branch from b44e43c to 219714d Compare April 23, 2025 06:30
@klensy
Copy link
Contributor

klensy commented Apr 23, 2025

Scope was added in #64856 without comment, so there no issues with somehow reverting it back?

@nnethercote
Copy link
Contributor Author

@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 Apr 23, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 23, 2025
… r=<try>

Streamline the `format` macro.

Removing the unnecessary local variable speeds up compilation a little.

r? `@ghost`
@bors
Copy link
Collaborator

bors commented Apr 23, 2025

⌛ Trying commit 219714d with merge 77bade5...

@nnethercote
Copy link
Contributor Author

Scope was added in #64856 without comment, so there no issues with somehow reverting it back?

I'm not sure. All the tests pass. Unlike back then, the block is now within the must_use call, giving an extra scope. The block itself is load-bearing; if I remove the { and } it slightly changes some error messages.

@bors
Copy link
Collaborator

bors commented Apr 23, 2025

☀️ Try build successful - checks-actions
Build commit: 77bade5 (77bade583880b062742296c0e9a2dc4cd1a389b3)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (77bade5): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

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.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

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

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
0.2% [0.2%, 0.2%] 1
Regressions ❌
(secondary)
1.8% [1.7%, 1.9%] 6
Improvements ✅
(primary)
-0.3% [-0.4%, -0.1%] 13
Improvements ✅
(secondary)
-0.1% [-0.1%, -0.1%] 1
All ❌✅ (primary) -0.2% [-0.4%, 0.2%] 14

Max RSS (memory usage)

Results (primary 2.1%)

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)
3.5% [0.7%, 12.2%] 10
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.3% [-3.4%, -1.5%] 3
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.1% [-3.4%, 12.2%] 13

Cycles

Results (primary -0.0%, secondary -2.4%)

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.4% [0.4%, 0.4%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.5% [-0.5%, -0.4%] 2
Improvements ✅
(secondary)
-2.4% [-2.4%, -2.4%] 1
All ❌✅ (primary) -0.0% [-0.5%, 0.4%] 4

Binary size

Results (primary -0.0%)

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

Bootstrap: 776.892s -> 774.802s (-0.27%)
Artifact size: 365.04 MiB -> 365.02 MiB (-0.01%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Apr 23, 2025
@cuviper
Copy link
Member

cuviper commented Apr 23, 2025

Scope was added in #64856 without comment, so there no issues with somehow reverting it back?

It is probably now benefiting from the 2024 scope change:
https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html

@nnethercote
Copy link
Contributor Author

The cargo-0.60.0 perf improvement is real. That was the motivating example -- I did some ad hoc profiling of where expressions are created and found that format! calls accounted for ~1% of all expressions created when compiling that benchmark.

The match-stress regression is puzzling. I can't reproduce when I profile local builds. When I run the Cachegrind repro command to profile the CI builds it says the difference is entirely in rustc_pattern_analysis::usefulness::compute_exhaustiveness_and_usefulness::<rustc_pattern_analysis::rustc::RustcPatCtxt>::{closure#0}. There is no line-level info, I think closure#0 is just |r| !r.pats.relevant so no idea what's happening there.

Removing the unnecessary local variable speeds up compilation a little.
@nnethercote nnethercote force-pushed the streamline-format-macro branch from 219714d to bc8df50 Compare April 27, 2025 20:56
@nnethercote
Copy link
Contributor Author

@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 Apr 27, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 27, 2025
… r=<try>

Streamline the `format` macro.

Removing the unnecessary local variable speeds up compilation a little.

r? `@ghost`
@bors
Copy link
Collaborator

bors commented Apr 27, 2025

⌛ Trying commit bc8df50 with merge 42bd627...

@bors
Copy link
Collaborator

bors commented Apr 27, 2025

☀️ Try build successful - checks-actions
Build commit: 42bd627 (42bd6276c0918c5943c8e76015a4bf68af24177f)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (42bd627): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

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.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

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

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.8% [1.7%, 1.9%] 6
Improvements ✅
(primary)
-0.3% [-0.3%, -0.3%] 3
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.3% [-0.3%, -0.3%] 3

Max RSS (memory usage)

Results (primary 1.5%, secondary 2.0%)

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)
2.8% [0.6%, 8.4%] 5
Regressions ❌
(secondary)
2.0% [2.0%, 2.0%] 1
Improvements ✅
(primary)
-1.9% [-2.9%, -0.9%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.5% [-2.9%, 8.4%] 7

Cycles

Results (primary 0.4%)

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

Binary size

Results (primary -0.1%)

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.1% [0.1%, 0.1%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.1% [-0.2%, -0.0%] 18
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.1% [-0.2%, 0.1%] 19

Bootstrap: 761.979s -> 763.313s (0.18%)
Artifact size: 365.07 MiB -> 365.10 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 28, 2025
@nnethercote nnethercote marked this pull request as ready for review April 28, 2025 01:01
@nnethercote
Copy link
Contributor Author

I think it's worth doing this for the small improvements on real-world code, which outweigh the weird regression on one artificial stress test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants