Reorder parsed_number_string_t fields to avoid padding (fixes #418) - #419
Merged
Merged
Conversation
Placing the parse_error field next to the booleans shrinks the struct from 72 to 64 bytes on 64-bit systems, recovering a large performance regression observed with MSVC. Add a static_assert to guard the size.
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.
Fixes #418.
Since commit 0e7a10a added the
parse_errorfield at the end ofparsed_number_string_t, padding grew the struct from 64 to 72 bytes on 64-bit systems. The reporter measured a ~1.75x slowdown with MSVC (19.9 ns/f → 11.2 ns/f after the fix on canada.txt).This PR moves
errornext to the booleans, which brings the struct back to 64 bytes (checked locally: 72 → 64 forchar,char16_tandchar32_t). No code builds the struct with aggregate initialization, so the new field order changes nothing else.It also adds a
static_assertintests/basictest.cppso the 64-byte size doesn't regress on 64-bit targets.Not done here: the issue also suggests giving
parse_errora 1-byte underlying type. That would save 8 more bytes on 32-bit targets but changes a public type, so I left it out.