-
-
Notifications
You must be signed in to change notification settings - Fork 167
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
Optimize performance for string literals in Display::fmt #286
Conversation
cb80183
to
9c712ab
Compare
Compiler is unable to generate as efficient code for `write!(f, "text")` as it does for `f.write_str("text")`. This PR checks if the `#[error("text")]` uses a simple string literal without the `{` and `}` characters, and without arguments, and uses `write_str` if so.
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.
Thanks!
Published in 1.0.57. |
thanks for merging and releasing it so fast! Do you know if it would be possible to detect a more advanced case when the formatting string is by itself, and the only argument is a fn fmt(...) {
let s = "string";
write!("{0}", s)
} P.S. Obviously all these things should be eventually done in the compiler... 🤞 |
I do not know of a way to optimize that. |
It would probably be worthwhile to create some new custom errors, but this commit doesn't do it yet. Also, update thiserror to take advantage of dtolnay/thiserror#286
It would probably be worthwhile to create some new custom errors, but this commit doesn't do it yet. Also, update thiserror to take advantage of dtolnay/thiserror#286
Compiler is unable to generate as efficient code for
write!(f, "text")
as it does forf.write_str("text")
. This PR checks if the#[error("text")]
uses a simple string literal without the{
and}
characters, and without arguments, and useswrite_str
if so.Fixes #285