Optimize 128-bit integer formatting#68
Merged
dtolnay merged 1 commit intodtolnay:masterfrom Mar 20, 2026
Merged
Conversation
The compiler is unaware of the restricted range of the input, so it is unable to optimize out the final division and modulus. By doing this manually, we get a nontrivial performance gain.
dtolnay
reviewed
Mar 19, 2026
Owner
dtolnay
left a comment
There was a problem hiding this comment.
Thanks!
All of this code is just copied from libcore. Please send this optimization there first, and then it can get synced here. I would prefer to diverge as little as possible.
Contributor
Author
|
Ah, I didn't realize it was a verbatim copy, just that it was largely copied. I'll do that momentarily. |
Zalathar
added a commit
to Zalathar/rust
that referenced
this pull request
Mar 19, 2026
…g, r=dtolnay Optimize 128-bit integer formatting The compiler is unaware of the restricted range of the input, so it is unable to optimize out the final division and modulus. By doing this manually, we get a nontrivial performance gain. r? @dtolnay (copied from dtolnay/itoa#68)
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Mar 19, 2026
…g, r=dtolnay Optimize 128-bit integer formatting The compiler is unaware of the restricted range of the input, so it is unable to optimize out the final division and modulus. By doing this manually, we get a nontrivial performance gain. r? @dtolnay (copied from dtolnay/itoa#68)
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Mar 19, 2026
…g, r=dtolnay Optimize 128-bit integer formatting The compiler is unaware of the restricted range of the input, so it is unable to optimize out the final division and modulus. By doing this manually, we get a nontrivial performance gain. r? @dtolnay (copied from dtolnay/itoa#68)
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Mar 19, 2026
…g, r=dtolnay Optimize 128-bit integer formatting The compiler is unaware of the restricted range of the input, so it is unable to optimize out the final division and modulus. By doing this manually, we get a nontrivial performance gain. r? @dtolnay (copied from dtolnay/itoa#68)
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Mar 19, 2026
…g, r=dtolnay Optimize 128-bit integer formatting The compiler is unaware of the restricted range of the input, so it is unable to optimize out the final division and modulus. By doing this manually, we get a nontrivial performance gain. r? @dtolnay (copied from dtolnay/itoa#68)
dtolnay
approved these changes
Mar 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The compiler is unaware of the restricted range of the input, so it is unable to optimize out the final division and modulus. By doing this manually, we get a nontrivial performance gain.
By running the included benchmark (
u128[max]/itoa) repeatedly, I see an improvement from 32.274 ns to 30.470 ns — a 5.6% gain.