Pack decode-table entries as niche-optimized NonZeroU32 - #36
Merged
Conversation
Store each decode-table entry as a single little-endian NonZeroU32
([b0, b1, b2, len]) instead of a { buf: [u8; 3], len } struct, so a
bulk-decode table read is one aligned load and the write one unaligned
4-byte store. `len` (1..=3) occupies the high byte, so the packed value
is never zero: Option<Entry> uses 0 as its None niche, giving incomplete
tables a four-byte entry whose "undefined byte" state is enforced by the
type rather than a sentinel.
Both complete and incomplete decoders now share the one Entry type,
defined in the parent decoder module. The incomplete decoder drops its
per-byte ASCII branch (with a single-load read it is a wash), and the
store is endian-normalized via to_le_bytes. Codegen and the generated
code_pages tables use the Entry::new(...) constructor form.
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.
Store each decode-table entry as a single little-endian
NonZeroU32([b0, b1, b2, len]) instead of a{ buf, len }struct, so a bulk-decode table read is one load and the write one store.len(1..=3) sits in the high byte, so the value is never zero —Option<Entry>uses0as itsNoneniche for undefined bytes in incomplete tables. Both decoders now share the oneEntrytype; the incomplete decoder drops its per-byte ASCII branch, and the store is endian-normalized viato_le_bytes.Speeds up bulk
decodeof mostly-ASCII input by ~12-15% (p=0.00);decode_bytea few percent faster. No API changes.