You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(txn)!: return values as Bytes sharing the cached page
BREAKING: `ReadTxn::get` and `WriteTxn::get` return `Option<Bytes>` rather
than `Option<Vec<u8>>`.
Every lookup copied its value out of the page it had just pinned, so a warm
read — no I/O, no decryption, the bytes already in memory — still allocated and
memcpy'd. Hold the page buffer as `Bytes` and hand back a slice of it: a
refcount bump instead of a copy, and the warm get path now allocates nothing at
all.
The returned handle keeps that buffer alive by itself, so it outlives the guard
and survives the page leaving the cache, and the bytes under it never change
because a write installs a new page rather than mutating the old one. That is
what makes the slice a stable snapshot of the version that was read rather than
a window onto whatever the page becomes.
It does hold the whole page for as long as it lives, which is the real cost:
code that keeps one small value from each of many pages should copy it out.
Both entry points say so.
Values that have no committed page to borrow from — an overflow chain, or a
write this transaction has not flushed — are still assembled into a buffer of
their own, and `Bytes` carries them without a second copy.
Chosen now because the return type is the part that cannot change later: the
internals can get faster after 0.1, the signature cannot.
0 commit comments