Skip to main content

Crate kevy_bytes

Crate kevy_bytes 

Source
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, then u8 tag holding the inline length (0..=22). The whole string lives in the value, no allocation.
  • Heap (64-bit): NonNull<u8> ptr (8) + usize len (8) + usize cap_and_tag (8). The high byte of cap_and_tag overlaps byte 23 of the union and is fixed at 0xFF (> 22) as the heap discriminator. The low 56 bits hold the heap capacity (up to 72 PB).
  • Heap (32-bit): NonNull<u8> ptr (4) + u32 len (4) + u32 cap (4) + 11-byte pad, then u8 tag fixed at 0xFF. Same 24-byte total, same discriminator byte at offset 23 — pointer / len fields are 32-bit-native so a wasm32-unknown-unknown build picks up the right size without shifting a usize past 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§

SmallBytes
A 24-byte owned byte string with inline small-string optimization.