-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Using &v
instead of v
arg in format!
does not inline, causing ~6% perf hit
#112156
Comments
@rustbot label A-codegen I-slow |
cc: @m-ou-se because it might be related to all the great format-AST related work |
Right now, every argument to format_args!() turns into a rust/library/core/src/fmt/rt.rs Lines 66 to 78 in 23f93a1
I don't expect llvm to be able to optimize that in any meaningful way. So I don't think this is something we can immediately solve. Longer term, a new implementation could do this very differently and perhaps tackle this issue.
I don't think the AST is enough to tell if a Perhaps we can special case |
Thanks @m-ou-se for the explanation. I was hoping that while argument is represented as a |
Per rust-lang#112156, using `&` in `format!` may cause a small perf delay, so I tried to clean up one module at a time format usage. This PR includes a few removals of the ref in format (they do compile locally without the ref), as well as a few format inlining for consistency.
Per rust-lang#112156, using `&` in `format!` may cause a small perf delay, so I tried to clean up one module at a time format usage. This PR includes a few removals of the ref in format (they do compile locally without the ref), as well as a few format inlining for consistency.
…Lapkin Optimize format usage Per rust-lang#112156, using `&` in `format!` may cause a small perf delay, so I tried to clean up one module at a time format usage. This PR includes a few removals of the ref in format (they do compile locally without the ref), as well as a few format inlining for consistency.
Optimize format usage Per rust-lang#112156, using `&` in `format!` may cause a small perf delay, so I tried to clean up one module at a time format usage. This PR includes a few removals of the ref in format (they do compile locally without the ref), as well as a few format inlining for consistency.
Avoid ref when using format! Clean up a few minor refs in `format!` macro, as it has a performance cost. Apparently the compiler is unable to inline `format!("{}", &variable)`, and does a run-time double-reference instead (format macro already does one level referencing). Inlining format args prevents accidental `&` misuse. See also rust-lang/rust#112156 changelog: none
I tried this code:
I expected
&i
to be inlined and be equivalent toformat!("{}", i)
Instead, in my benchmarking tests I see about 6% performance hit, and assembly has a non-inlined function.
Relevant links
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: