Repository navigation
byte_record: validate non-ASCII records in one pass - #441
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
`validate` ran `str::from_utf8` once per field as soon as the record had a single non-ASCII byte. Now the whole buffer is checked once and the field ends are checked to be on char boundaries, which is enough for every field to be valid on its own. The per-field loop is still used to build the error. Reading 15 MB of mostly non-ASCII data into `StringRecord` goes from ~500 MB/s to ~615 MB/s here. ASCII input is unaffected.
patrick-immometrica
marked this pull request as ready for review
November 14, 2026 11:11
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.
Once a record has any non-ASCII byte,
validatefalls back tostr::from_utf8per field. For data that's mostly non-ASCII (names, addresses in non-Latin scripts) that's a lot of short calls per record.This checks the whole buffer once and then makes sure every field end lands on a char boundary. If both hold, each field is valid UTF-8 on its own. Otherwise it falls through to the existing per-field loop, so error positions don't change. The ASCII fast path stays first, since dropping it made ASCII input about 15% slower.
Reading a 15 MB non-ASCII file with
read_recordinto aStringRecord:ASCII files (game, worldcitiespop) show no change. Added a test for a codepoint split across two fields, which is the case the boundary check is there for.
Related: #187, #410.