Replace arc-swap with manual AtomicPtr#695
Closed
ibraheemdev wants to merge 3 commits intosalsa-rs:masterfrom
Closed
Replace arc-swap with manual AtomicPtr#695ibraheemdev wants to merge 3 commits intosalsa-rs:masterfrom
arc-swap with manual AtomicPtr#695ibraheemdev wants to merge 3 commits intosalsa-rs:masterfrom
Conversation
✅ Deploy Preview for salsa-rs canceled.
|
CodSpeed Performance ReportMerging #695 will improve performances by 12.42%Comparing Summary
Benchmarks breakdown
|
Contributor
|
Wow, this is huge. I'd prefer for @nikomatsakis to review this change because I have little to no knowledge around this code but happy to take a look if Niko can't make the time. |
Veykril
reviewed
Feb 19, 2025
Co-authored-by: Lukas Wirth <[email protected]>
Co-authored-by: Lukas Wirth <[email protected]>
nikomatsakis
approved these changes
Feb 20, 2025
Member
nikomatsakis
left a comment
There was a problem hiding this comment.
I believe this is correct. r=me
Contributor
|
@ibraheemdev this needs a rebase. Happy to merge once that's done. |
Contributor
|
Closing this PR as it landed in #737. |
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.
It seems that we don't actually need arc-swap for the memo table, because our
deleted_entriesqueue takes care of deferring reclamation until there are no live borrows of a given memo. arc-swap does a lot of extra bookkeeping; replacing it with a manualAtomicPtrobject speeds up red-knot's incremental performance by about 15%. This should also make it easier to test with loom/shuttle.You'll notice that none of the safety requirements of the
MemoTablefunctions actually change with this PR, so I believe it is sound. The one catch is that we have to avoid returningManuallyDrop<Box<T>>and instead work withNonNulluntil the allocation is actually freed and we can assert uniqueness, asBoxis a noalias type (at least under the current rules).I also played around with using
boxcar::Vecinstead of the current lock, but the lock is actually relatively uncontended and fine-grained and it was hard to balance cold and incremental performance with a lock-free implementation.