Repository navigation
perf(once-map): build FromIterator unlocked and reuse duplicate-key entries - #453
Merged
Merged
Conversation
8 tasks done
Move completed values out of `Entry` via `Arc::try_unwrap` whenever the caller holds the sole remaining reference at retrieval time, eliminating `V::clone()` on uncontended `work` and `try_work` calls without adding state to `Group`. Signed-off-by: tison <[email protected]>
…ntries Populate the backing `HashTable` before wrapping it in `Mutex` in `OnceMap::from_iter`, avoiding per-element lock acquisitions and updating existing `Entry` slots in place via `find_mut` and `Arc::get_mut` on duplicate keys without extra allocations or bucket pre-reservation. Also remove the single-use `Entries` alias and stale sharded-table comments, and add `once_map::build` benchmarks for distinct- and duplicate-key collection. Co-authored-by: Orthur <[email protected]> Signed-off-by: tison <[email protected]>
tisonkun
force-pushed
the
perf/keyed-coalescing-and-elastic-shrink
branch
from
November 22, 2026 14:54
1864e91 to
62f394c
Compare
This reverts commit c36a5d4. `singleflight::Group` requires `V: Clone` to share values across coalesced callers, so idiomatic callers pass cheaply cloned payloads (`Arc<T>`, `Bytes`, or scalars). Because `OnceCell::get_or_try_init` already returns `&V`, discarding that reference to attempt `Arc::try_unwrap` on the entry regresses uncontended scalar calls (`leader_success`: +5.4%) and adds failed atomic `compare_exchange` traffic across shared `Arc` headers on coalesced fan-out (`complete_coalesced/16`: +26.5%). Restore the direct `v.clone()` return path so idiomatic workloads pay no atomic unwrap overhead. Signed-off-by: tison <[email protected]>
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.
Summary
Part of #445 (Wave 2).
Closes #355.
OnceMap::from_iterpreviously inserted each(K, V)pair by delegating through the generalOnceMapinsertion path, acquiring the table mutex on every element and allocating a freshArc<Entry<K, V>>whenever duplicate keys appeared.This pull request populates the backing
HashTabledirectly before wrapping it inMutex, and updates duplicate-key entries in place viaHashTable::find_mutandArc::get_mutwithout reallocating theArcor pre-reserving extra buckets on full tables. It supersedes #355 while retainingCo-authored-bycredit and preserving the duplicate-key destructor panic cleanup from #409.Benchmarks
Apple M4 Max (
cargo bench -p benchmarks --bench primitives -- once_map::build, median of 5 runs):main(7054cef)c685930)once_map::build::collect_distinct_keys/64once_map::build::collect_distinct_keys/1024once_map::build::collect_duplicate_keys/64once_map::build::collect_duplicate_keys/1024