pub enum Value {
Str(SmallBytes),
Int(i64),
ArcBulk(Arc<Box<[u8]>>),
Hash(Arc<HashData>),
List(Arc<ListData>),
Set(Arc<SetData>),
ZSet(Arc<ZSetData>),
Stream(Arc<StreamData>),
SmallSetInline(SmallSetData),
SmallHashInline(SmallHashData),
SmallListInline(SmallListData),
SmallZSetInline(SmallZSetData),
}Expand description
A stored value. One variant per Redis type.
The collection variants live behind a shared pointer (Arc) so the
enum is only as big as Str (24 B) + tag = 32 B, not the 56 B ZSetData
— every Entry (incl. the common string case) is then ~48 B instead of
~80 B, so the bucket array is ~40% denser/smaller (fewer cache misses on
a large keyspace, less RSS). The extra pointer-chase lands only on
collection ops, not the hot string GET path.
Arc (same 8 B as the previous Box) is what makes O(short-pause)
persistence possible: crate::Store::collect_snapshot bumps each
collection’s refcount instead of serializing it, and a background thread
walks the frozen payloads at leisure. Mutations go through
std::sync::Arc::make_mut — a single uniqueness check (the steady
state, no snapshot in flight) or a copy-on-write deep clone when a
snapshot still holds the payload.
Str holds a SmallBytes (24 B, same size as Vec<u8>) so byte strings
up to 22 bytes live inline inside the bucket, killing the second cache
miss the value pointer-chase used to cost on large-keyspace GETs.
Clone is the snapshot-collect primitive: Str copies its bytes
(inline = 24 B memcpy; heap = one allocation), collections bump a
refcount. See crate::Store::collect_snapshot.
Variants§
Str(SmallBytes)
Int(i64)
L2 (2026-06-21, lessons from valkey OBJ_ENCODING_INT): when a SET
stores a clean canonical i64 ASCII string (parses round-trip), we
keep the integer as i64 rather than as 22 B of inline bytes.
Wins on INCR (in-place += delta, no parse / no format / no
SmallBytes wrap) and on memory (8 B vs 24 B). GET formats it via
a per-Store scratch buffer.
ArcBulk(Arc<Box<[u8]>>)
L1 (2026-06-21) / v1.29 Option A (2026-06-29): values larger
than BULK_THRESHOLD bytes get stored behind an
Arc<Box<[u8]>> instead of a heap-backed SmallBytes. The Arc
lets the io_uring reactor’s reply path borrow the bytes across
the SQE→CQE window safely (Arc clone keeps them alive even if
the keyspace mutates) — the prerequisite for the writev
zero-copy bulk reply path, which skips the per-GET memcpy from
value storage into the per-conn output buffer.
Why Arc<Box<[u8]>> and not Arc<[u8]>: Arc<[u8]> is a
DST-backed ArcInner<[u8]> = { strong, weak, [u8; N] } whose
data slot sits past the refcount words. Arc::from(Vec<u8>)
allocates a fresh ArcInner and copy_from_slices the bytes
— a hard mandatory 64 KiB memcpy on every big SET. With
Arc<Box<[u8]>>, the Box<[u8]> wrapper occupies the Arc’s
data slot (16 B), pointing AT an unchanged heap buffer; so
Arc::new(vec.into_boxed_slice()) is truly zero-copy
(the boxed slice’s allocation stays put — only the 32-byte
ArcInner is freshly malloced). Per-GET cost: one extra
pointer dereference (&**arc to get &[u8]), measured to be
negligible vs the per-SET memcpy savings. See
bench/PERF-FINDING-2026-06-29-arc-from-box-memcpys.md for
the empirical perf-record evidence of the original
Arc<[u8]> mandatory copy.
Small values stay on Str(SmallBytes) because the inline
cache-line storage beats an Arc indirection for the common case.
Hash(Arc<HashData>)
List(Arc<ListData>)
Set(Arc<SetData>)
ZSet(Arc<ZSetData>)
Stream(Arc<StreamData>)
SmallSetInline(SmallSetData)
v1.25 A.7 O5 (valkey-orthodox encoding switch): tiny sets (1-N
short members) live inline in 24 bytes instead of behind
Arc<SetData> — matches valkey’s OBJ_ENCODING_LISTPACK for
sets, which is what redis-benchmark -t sadd default -r 0
(cardinality stays at 1 forever, single 20-byte literal member)
measures. On overflow (crate::small_set::SmallSetData::try_add
returns NoRoom) the set is promoted to Value::Set(Arc<SetData>)
— the Swiss-table path that wins for larger cardinalities.
SmallHashInline(SmallHashData)
v1.25 A.8 (extension of A.7 to hashes): tiny hashes
(1-2 short field-value pairs) live inline in 24 bytes; promoted
to Value::Hash(Arc<HashData>) on overflow. Mirrors valkey’s
OBJ_ENCODING_LISTPACK for hashes.
SmallListInline(SmallListData)
v1.25 A.8: tiny lists inline encoding; promoted to
Value::List(Arc<ListData>) on overflow.
SmallZSetInline(SmallZSetData)
v1.25 A.8: tiny sorted sets inline encoding; promoted to
Value::ZSet(Arc<ZSetData>) on overflow.
Implementations§
Source§impl Value
impl Value
Sourcepub fn weight(&self) -> u64
pub fn weight(&self) -> u64
Approximate heap bytes the value owns. Excludes the inline Entry /
bucket slot — that’s a separate per-entry constant accounted by the
store. Walks collections, so prefer the cached Entry::weight for
hot-path accounting and only call this when bootstrapping or after a
load-from-snapshot.
Sourcepub fn is_heap_heavy(&self) -> bool
pub fn is_heap_heavy(&self) -> bool
Whether this value’s Drop is heavy enough to deserve being
shipped to the bio thread instead of freed inline. Fast: every
variant decides off a sub-field cheap to inspect (no recursive
walk), so it’s safe to call on every overwrite-SET on the hot
path. The threshold is intentionally conservative — small Arcs
- every short string stay on inline-drop where jemalloc small- class is sub-µs and a cross-thread hand-off would lose.