-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Integer to_string
is slow
#135543
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
Labels
A-fmt
Area: `core::fmt`
C-optimization
Category: An issue highlighting optimization opportunities or PRs implementing such
Comments
FWIW, my understanding is that formatting goes through dynamic dispatch, as a deliberate choice to reduce the binary size bloat from inlining all formatting |
This comment has been minimized.
This comment has been minimized.
You can try the |
To be noted that there is work in progress to improve this situation. Already two PRs were merged:
Hopefully more will follow soon. :) |
bors
added a commit
to rust-lang-ci/rust
that referenced
this issue
Jan 30, 2025
…string, r=<try> Optimize `ToString` implementation for integers Part of rust-lang#135543. Follow-up of rust-lang#133247 and rust-lang#128204. Rather than writing pretty bad benchers like I did last time, `@workingjubilee:` do you have a suggestion on how to check the impact on performance for this PR? Thanks in advance! r? `@workingjubilee`
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-fmt
Area: `core::fmt`
C-optimization
Category: An issue highlighting optimization opportunities or PRs implementing such
On my machine, the following code runs in 3 seconds in stable version, release build:
whereas the C++ counterpart runs in 1.2 seconds with
-O2
:I've found that most of the time loss comes from passing
&str
through a formatter instead of directlymemcpy
ing; replacingto_string
with _fmt with.to_owned()
at the end speeds it up to around 1.6s.The text was updated successfully, but these errors were encountered: