Repository navigation
A string write that does not return the old value does not read it - #3160
Open
matrixarkai wants to merge 1 commit into
Open
matrixarkai wants to merge 1 commit into
matrixarkai wants to merge 1 commit into
Conversation
matrixarkai
force-pushed
the
perf/a-string-write-that-returns-nothing-reads-nothing
branch
from
November 15, 2026 23:46
3b66d15 to
915de33
Compare
matrixarkai
force-pushed
the
perf/a-string-write-that-returns-nothing-reads-nothing
branch
from
November 16, 2026 02:53
6a777f2 to
93e9a41
Compare
matrixarkai
marked this pull request as ready for review
November 16, 2026 02:56
SET, SET NX, SET XX and SET KEEPTTL reach the shard as one conditional write, which read the key's whole old value into a Vec before deciding anything and dropped it unread unless the caller asked for it back. An unconditional write that returns nothing now reads nothing, and NX and XX ask whether the key is there from its row, with no block read. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
matrixarkai
force-pushed
the
perf/a-string-write-that-returns-nothing-reads-nothing
branch
from
November 16, 2026 04:29
93e9a41 to
79591d1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SET, SET NX, SET XX and SET KEEPTTL reach the shard as one conditional write. It read the key's whole old value into a
Vecbefore deciding anything and dropped it unread unless the caller asked for it back: a copy of every byte of the value about to be replaced, and a block-store read when the old frame was not cached. An unconditional write that returns nothing now reads nothing, and NX/XX ask whether the key is there from its row in memory (no block read). A write that asks for the old value (GETSET,SET .. GET) still reads it.No stored byte, log record or wire byte changes; the write that lands writes what it wrote. One behaviour differs, and only for a damaged store: a key whose row exists but whose block cannot be read now counts as present for NX/XX.
Measured (counting allocator, release,
alloc-probe, oneexecuteper operation, 40 operations over 8 existing keys; before = the replaced read selected by a temporary switch in a scratch build of the same tree, after = this change):SET .. KEEPTTLis the same figure. The floor is the plainStringSetcommand (1 MiB: 5,380,356 bytes, 46.4 allocs): a SET over an existing key now costs what a SET always cost. In CI, over a 256 KiB value: SET 790,760 bytes (the write that asks for the old value, the control, 1,594,882), XX 790,760, a refused NX 262,151 where it read the old value before (1,049,807 in the earlier push of this branch).Plant: #3169 restores the old read under the same guard; the guard must fail with the old counts (CI run linked there). Guards, pinned by exact name in
rust-ci.yml:a_conditional_write_answers_what_it_always_answered(every condition x present/absent x return-old x KEEPTTL, against known answers, the deadline, and a reload),the_value_a_write_leaves_is_the_value_a_read_returns(nine widths either side of the store's size classes, over each other), and the probea_string_overwrite_does_not_copy_the_old_value, whose control is the write that asks for the old value.Not measured: instructions; wall time; a cold-cache NX/XX (the row answer reads no block at all, so there is nothing left to time). A first variant read the block through the cache's shared bytes for NX/XX and was measured worse on a cold frame (a copy into an
Arc), which is why presence is the row. Net about 25 lines of code, 300 of test.🤖 Generated with Claude Code