Repository navigation
Write minus sign without a branch - #73
Open
patrick-immometrica wants to merge 1 commit into
Open
patrick-immometrica wants to merge 1 commit into
patrick-immometrica wants to merge 1 commit into
Conversation
The branch on the sign mispredicts when formatting a mix of positive and negative values. Write the '-' unconditionally and only move the start offset for negative values.
patrick-immometrica
marked this pull request as ready for review
November 5, 2026 10:32
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.
if self < 0 { offset -= 1; buf[offset].write(b'-'); }turns into a real branch, which mispredicts on input where the signs are mixed. Writing the-unconditionally, one byte in front of the digits, and only moving the start offset for negative numbers avoids that. There is always room for the extra byte, because the magnitude takes at mostMAX_STR_LEN - 1bytes.Numbers are from an Apple M5 (aarch64). Both versions are linked into one binary, alternating 300 rounds over the same 1024 random values and keeping the min; ns per call. Repeating master against master stays within about ±4%.
Single-sign input stays the same. I added tests for i64::MAX and -1. There were no tests for a positive value at the type's limit or for a one-digit negative value, which are the two cases an off-by-one in the offset would break.
This touches the same line as #72, so whichever goes in second needs a trivial rebase.