Repository navigation
Release placeholder keys when unsync loaders fail - #132
Merged
Merged
Conversation
Deref borrows the resident value through the cached pointer. The weight guard uses the slot token to recompute weight on drop. Exercise shared and mutable reborrows on a guard moved by value and check weight accounting when a live guard drops during unwind.
Keep the cached value pointer with the PlaceholderId bound. Wrap each loader placeholder in the current Guard representation so drop releases the key on failure.
arthurprs
marked this pull request as ready for review
November 22, 2026 12:06
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.
An unsync convenience loader creates a placeholder that owns the key before calling the loader. If the loader returns an error or panics, the placeholder can retain its key until a retry, removal, clear, or cache drop. The placeholder counts toward neither
len()nor resident capacity.Both convenience loaders now hold the placeholder in the existing
Guardwhile calling the loader. Dropping the guard removes the unfilled placeholder on error or unwind. The regression tests check that both loaders release the owned key and can retry successfully. An immediate retry creates a fresh placeholder and records a miss when statistics are enabled.On a resident hit,
get_or_insert_withreturns the reference from the resident lookup and skips the follow-up slab access by token. After inserting on a miss, it checks the slot to see whether the value was admitted. The mutable loader looks up the slot to construct its weight-trackingRefMut.RefMutcaches a raw pointer to the resident value so dereferencing the guard can skip the slab lookup. The exclusive shard borrow keeps the resident in place while the guard is live. Drop uses the slot token to recompute weight. The guard stores one additional pointer.In five local interleaved runs on Rust 1.97.1,
9e173ddlowered median latency for repeatedget_or_insert_withhits on one residentu64key by 10.4–10.9% (0.63–0.66 ns/op) versus the token-lookup revision (e334d8d). Each pair timed 8,192 hits per revision on an AMD Ryzen AI Max+ Pro 395, with the order reversed between pairs.