Skip to content

Pack decode-table entries as niche-optimized NonZeroU32 - #36

Merged
bonega merged 1 commit into
masterfrom
refactor/pack-entry-nonzerou32
Jul 2, 2026
Merged

Pack decode-table entries as niche-optimized NonZeroU32#36
bonega merged 1 commit into
masterfrom
refactor/pack-entry-nonzerou32

Conversation

@bonega

@bonega bonega commented Jul 2, 2026

Copy link
Copy Markdown
Owner

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> uses 0 as its None niche for undefined bytes in incomplete tables. Both decoders now share the one Entry type; the incomplete decoder drops its per-byte ASCII branch, and the store is endian-normalized via to_le_bytes.

Speeds up bulk decode of mostly-ASCII input by ~12-15% (p=0.00); decode_byte a few percent faster. No API changes.

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.
@bonega
bonega merged commit 730979b into master Jul 2, 2026
7 checks passed
@bonega bonega mentioned this pull request Jul 17, 2026
bonega added a commit that referenced this pull request Jul 17, 2026
Perf/code-size only, no API changes.

- Bulk decode of mostly-ASCII input ~12-15% faster (niche-packed
  NonZeroU32 table entries, #36).
- Monomorphized bulk decode ~40%/34% smaller from unaligned word
  reads, throughput unchanged (#39).
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.

1 participant