Skip to content

Reorder parsed_number_string_t fields to avoid padding (fixes #418) - #419

Merged
lemire merged 1 commit into
mainfrom
fix-418-struct-layout
Oct 4, 2026
Merged

lemire merged 1 commit into
mainfrom
fix-418-struct-layout

Conversation

@lemire

@lemire lemire commented Oct 4, 2026 •

Copy link
Copy Markdown
Member

Fixes #418.

Since commit 0e7a10a added the parse_error field at the end of parsed_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 error next to the booleans, which brings the struct back to 64 bytes (checked locally: 72 → 64 for char, char16_t and char32_t). No code builds the struct with aggregate initialization, so the new field order changes nothing else.

It also adds a static_assert in tests/basictest.cpp so the 64-byte size doesn't regress on 64-bit targets.

Not done here: the issue also suggests giving parse_error a 1-byte underlying type. That would save 8 more bytes on 32-bit targets but changes a public type, so I left it out.

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.
@lemire
lemire merged commit 3e4f80f into main Oct 4, 2026
66 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Performance regression since v6.1.4

1 participant