-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Use write_str() instead of write!() when possible #109175
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
Conversation
r? @lcnr (rustbot has picked a reviewer for you, use r? to override) |
Reduces code size
cc @davidtwco, @compiler-errors, @JohnTitor, @TaKO8Ki Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri
cc @davidtwco, @compiler-errors, @JohnTitor, @TaKO8Ki Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
Does the optimization difference disappear with #106824 ? It seems like the existing style is the opposite of this PR. Can/should we have a tidy check to enforce this style? |
LocalValue::Live(Operand::Immediate(Immediate::Uninit)) => { | ||
write!(fmt, " is uninitialized")? | ||
fmt.write_str(" is uninitialized")? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless benchmarks show that this is actually perf-critical, I'd rather stick to the old code and prioritize code readability and uniformity. It's better (IMO) to have the same uniform code for format strings with and without any interpolation.
@bors try @rust-timer queue Let's see the perf. effect of this. I also wonder whether this is required after Mara's inlining PR. |
This comment has been minimized.
This comment has been minimized.
⌛ Trying commit e867567 with merge f48221e382b2eb037dcb7d7de468168f7069c810... |
#106824 is nice, but does not address the same thing. It simplifies The closure-based rewrite of formatting #101568 can achieve the same result in optimized code. |
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Hm, it shouldn't be too hard to fix that. |
I've added it to the list in #99012:
|
@rust-timer build f48221e382b2eb037dcb7d7de468168f7069c810 let's still have a look at perf so we can add the data to the tracking issue, but close this PR once perf is done. |
oh perf is just swamped. will take a bit to get a result here |
Finished benchmarking commit (f48221e382b2eb037dcb7d7de468168f7069c810): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking 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 Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis 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.
CyclesThis benchmark run did not return any relevant results for this metric. |
Looks neutral with some smaller wins that may be noise. Changing this isn't worth it in the compiler, but cleaning it up in general is still something to explore |
I think that the wins look like more than noise. But I agree that it's probably not worth to merge this, as the wins are not big enough to justify the "worse/inconsistent" code style. Especially if there's hope that Mara's changes can win the perf back here soon-ish. |
I was looking at the non-relevant results and it seemed to me that there are a lot of green results. In any case, the wins are definitely small, that's true :) |
write!(formatter, "literal")
needlessly constructsfmt::Arguments::new_v1
that doesn't fully optimize out. OTOHformatter.write_str("literal")
compiles to just a function call, so it's quicker to compile and results in smaller binaries.I took care to correct uses of
{{
and}}
in the formatting string.