Expand description
SmallBytes — a 24-byte small-byte-string with inline-SSO optimization.
Layout (little-endian only): a union of two 24-byte variants, distinguished by the byte at offset 23:
- Inline:
[u8; 23]data, thenu8tag holding the inline length (0..=22). The whole string lives in the value, no allocation. - Heap (64-bit):
NonNull<u8>ptr (8) +usizelen (8) +usizecap_and_tag (8). The high byte ofcap_and_tagoverlaps byte 23 of the union and is fixed at0xFF(> 22) as the heap discriminator. The low 56 bits hold the heap capacity (up to 72 PB). - Heap (32-bit):
NonNull<u8>ptr (4) +u32len (4) +u32cap (4) + 11-byte pad, thenu8tag fixed at0xFF. Same 24-byte total, same discriminator byte at offset 23 — pointer / len fields are 32-bit-native so awasm32-unknown-unknownbuild picks up the right size without shifting ausizepast its bit width.
The 64-bit layout is the one the kevy server runs on, and is locked against perf-affecting changes (cfg-gated 32-bit alternative lives alongside it without touching any 64-bit code path).
This lets us store every byte string up to 22 bytes — covering the vast
majority of Redis-style values — without any pointer-chase, while keeping
size_of::<SmallBytes>() == 24 (same as Vec<u8>). Used by kevy-store
to make Value::Str(SmallBytes) fit alongside the boxed collection
variants and keep Entry at 48 B.
Unions§
- Small
Bytes - A 24-byte owned byte string with inline small-string optimization.