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

improve format impl for literals #97480

Merged
merged 2 commits into from
May 30, 2022

Conversation

conradludgate
Copy link
Contributor

The basic idea of this change can be seen here https://godbolt.org/z/MT37cWoe1.

Updates the format impl to have a fast path for string literals and the default path for regular format args.

This change will allow format!("string literal") to be used interchangably with "string literal".to_owned().

This would be relevant in the case of f!"string literal" being legal (rust-lang/rfcs#3267) in which case it would be the easiest way to create owned strings from literals, while also being just as efficient as any other impl

@rust-highfive
Copy link
Collaborator

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with r? rust-lang/libs-api @rustbot label +T-libs-api -T-libs to request review from a libs-api team reviewer. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@rust-highfive
Copy link
Collaborator

r? @joshtriplett

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 28, 2022
library/alloc/src/fmt.rs Outdated Show resolved Hide resolved
@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label May 28, 2022
@joshtriplett
Copy link
Member

@bors r+ rollup=never

@bors
Copy link
Contributor

bors commented May 28, 2022

📌 Commit 738d100438d9b099fed604cfa3b1eae47a191a43 has been approved by joshtriplett

@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 May 28, 2022
library/alloc/src/fmt.rs Outdated Show resolved Hide resolved
@conradludgate
Copy link
Contributor Author

How does one re-request a review 😅

@Dylan-DPC
Copy link
Member

@bors r=joshtriplett

@bors
Copy link
Contributor

bors commented May 30, 2022

📌 Commit 5dd0fe3 has been approved by joshtriplett

@bors
Copy link
Contributor

bors commented May 30, 2022

⌛ Testing commit 5dd0fe3 with merge 4a8d2e3...

@bors
Copy link
Contributor

bors commented May 30, 2022

☀️ Test successful - checks-actions
Approved by: joshtriplett
Pushing 4a8d2e3 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 30, 2022
@bors bors merged commit 4a8d2e3 into rust-lang:master May 30, 2022
@rustbot rustbot added this to the 1.63.0 milestone May 30, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (4a8d2e3): comparison url.

Instruction count

  • Primary benchmarks: 😿 relevant regressions found
  • Secondary benchmarks: 🎉 relevant improvement found
mean1 max count2
Regressions 😿
(primary)
0.4% 0.5% 4
Regressions 😿
(secondary)
N/A N/A 0
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
-1.5% -1.5% 1
All 😿🎉 (primary) 0.4% 0.5% 4

Max RSS (memory usage)

Results
  • Primary benchmarks: 😿 relevant regressions found
  • Secondary benchmarks: 🎉 relevant improvements found
mean1 max count2
Regressions 😿
(primary)
2.3% 5.7% 4
Regressions 😿
(secondary)
N/A N/A 0
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
-4.6% -4.8% 2
All 😿🎉 (primary) 2.3% 5.7% 4

Cycles

Results
  • Primary benchmarks: no relevant changes found
  • Secondary benchmarks: mixed results
mean1 max count2
Regressions 😿
(primary)
N/A N/A 0
Regressions 😿
(secondary)
2.2% 2.2% 1
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
-3.0% -3.0% 1
All 😿🎉 (primary) N/A N/A 0

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression

Footnotes

  1. the arithmetic mean of the percent change 2 3

  2. number of relevant changes 2 3

@rustbot rustbot added the perf-regression Performance regression. label May 30, 2022
@pnkfelix
Copy link
Member

pnkfelix commented Jun 1, 2022

Visiting for weekly rustc-perf performance triage.

  • This is adding a fast-path so that format!("literal") will compile into the same code as "literal".to_owned().
  • The primary regression is solely contained to bitmaps.
  • Its possible that the regression to bitmaps is due to format!("literal") being totally unused in that code; all instances of format! there take an additional argument.
    So its possible that the extra code to check about whether to use the fast-path is slowing things down there.
  • But I personally don't believe that explanation here: Unless I'm misunderstanding the code, there is some amount of macro-expansion into multiple instances of format!, but
    most of the expanded code is going to be dominated by all the impl blocks, not the relatively few format! instances. (Unless I massively misunderstand how the macros and/or codegen and/or inlining end up linking up here.)
  • So: I don't believe the best hypothesis I have for what is happening here.
  • But I also do not think the regression here is large enough to warrant further investigation.
  • Marking as triaged.

@rustbot label: perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Jun 1, 2022
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. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. 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.