-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Evaluate std::fmt::Arguments::new_const()
during Compile Time
#131663
Evaluate std::fmt::Arguments::new_const()
during Compile Time
#131663
Conversation
r? @chenyukang rustbot has assigned @chenyukang. Use |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
…<try> Evaluate `std::fmt::Arguments::new_const()` during Compile Time Fixes rust-lang#128709 This PR aims to optimize calls to string formating macros without any arguments by evaluating `std::fmt::Arguments::new_const()` in a const context. Currently, `println!("hola")` compiles to `std::io::_print(std::fmt::Arguments::new_const(&["hola\n"]))`. With this PR, `println!("hola")` compiles to `std::io::_print(const { std::fmt::Arguments::new_const(&["hola\n"]) })`. This is accomplished in two steps: 1. Const stabilize `std::fmt::Arguments::new_const()`. 2. Wrap calls to `std::fmt::Arguments::new_const()` in an inline const block when lowering the AST to HIR. This reduces the generated code to a `memcpy` instead of multiple `getelementptr` and `store` instructions even with `-C no-prepopulate-passes -C opt-level=0`. Godbolt for code comparison: https://rust.godbolt.org/z/P7Px7de6c This is a safe and sound transformation because `std::fmt::Arguments::new_const()` is a trivial constructor function taking a slice containing a `'static` string literal as input. CC rust-lang#99012
This comment has been minimized.
This comment has been minimized.
7638733
to
d235b47
Compare
This comment has been minimized.
This comment has been minimized.
d235b47
to
96bdf88
Compare
This comment has been minimized.
This comment has been minimized.
96bdf88
to
ff11342
Compare
Some changes occurred in coverage tests. cc @Zalathar |
This comment has been minimized.
This comment has been minimized.
ff11342
to
558d241
Compare
This comment has been minimized.
This comment has been minimized.
558d241
to
f361a33
Compare
This comment has been minimized.
This comment has been minimized.
f361a33
to
95b1d81
Compare
This PR modifies cc @jieyouxu |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
…<try> Evaluate `std::fmt::Arguments::new_const()` during Compile Time Fixes rust-lang#128709 This PR aims to optimize calls to string formating macros without any arguments by evaluating `std::fmt::Arguments::new_const()` in a const context. Currently, `println!("hola")` compiles to `std::io::_print(std::fmt::Arguments::new_const(&["hola\n"]))`. With this PR, `println!("hola")` compiles to `std::io::_print(const { std::fmt::Arguments::new_const(&["hola\n"]) })`. This is accomplished in two steps: 1. Const stabilize `std::fmt::Arguments::new_const()`. 2. Wrap calls to `std::fmt::Arguments::new_const()` in an inline const block when lowering the AST to HIR. This reduces the generated code to a `memcpy` instead of multiple `getelementptr` and `store` instructions even with `-C no-prepopulate-passes -C opt-level=0`. Godbolt for code comparison: https://rust.godbolt.org/z/P7Px7de6c This is a safe and sound transformation because `std::fmt::Arguments::new_const()` is a trivial constructor function taking a slice containing a `'static` string literal as input. CC rust-lang#99012
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (814ddfe): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowBenchmarking 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 @bors rollup=never Instruction countThis 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.
Max RSS (memory usage)Results (primary 2.3%, secondary 1.9%)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.
CyclesResults (primary 1.8%, secondary -0.6%)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.
Binary sizeResults (primary 0.1%, secondary 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.
Bootstrap: 782.597s -> 784.903s (0.29%) |
95b1d81
to
18220bd
Compare
☔ The latest upstream changes (presumably #132020) made this pull request unmergeable. Please resolve the merge conflicts. |
I don't know what's causing the large number of regressions. Please let me know if it's better to close this. |
18220bd
to
e20cc8e
Compare
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
…<try> Evaluate `std::fmt::Arguments::new_const()` during Compile Time Fixes rust-lang#128709 This PR aims to optimize calls to string formating macros without any arguments by evaluating `std::fmt::Arguments::new_const()` in a const context. Currently, `println!("hola")` compiles to `std::io::_print(std::fmt::Arguments::new_const(&["hola\n"]))`. With this PR, `println!("hola")` compiles to `std::io::_print(const { std::fmt::Arguments::new_const(&["hola\n"]) })`. This is accomplished by wrapping calls to `std::fmt::Arguments::new_const()` in an inline const block when lowering the AST to HIR. This reduces the generated code to a `memcpy` instead of multiple `getelementptr` and `store` instructions even with `-C no-prepopulate-passes -C opt-level=0`. Godbolt for code comparison: https://rust.godbolt.org/z/P7Px7de6c This is a safe and sound transformation because `std::fmt::Arguments::new_const()` is a trivial constructor function taking a slice containing a `'static` string literal as input. CC rust-lang#99012
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (1e4519d): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowBenchmarking 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 @bors rollup=never Instruction countThis 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.
Max RSS (memory usage)Results (primary 1.9%, secondary 2.7%)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.
CyclesResults (primary 2.6%, secondary -0.9%)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.
Binary sizeResults (primary 0.2%, secondary 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.
Bootstrap: 783.63s -> 779.85s (-0.48%) |
@veera-sivarajan do you want to continue to resolve the performance issue? |
Ah no, I don't have anything to add. Will close this now. |
Fixes #128709
This PR aims to optimize calls to string formating macros without any arguments by evaluating
std::fmt::Arguments::new_const()
in a const context.Currently,
println!("hola")
compiles tostd::io::_print(std::fmt::Arguments::new_const(&["hola\n"]))
.With this PR,
println!("hola")
compiles tostd::io::_print(const { std::fmt::Arguments::new_const(&["hola\n"]) })
.This is accomplished by wrapping calls to
std::fmt::Arguments::new_const()
in an inline const block when lowering the AST to HIR.This reduces the generated code to a
memcpy
instead of multiplegetelementptr
andstore
instructions even with-C no-prepopulate-passes -C opt-level=0
. Godbolt for code comparison: https://rust.godbolt.org/z/P7Px7de6cThis is a safe and sound transformation because
std::fmt::Arguments::new_const()
is a trivial constructor function taking a slice containing a'static
string literal as input.CC #99012