Skip to content

Comments

Replace arc-swap with manual AtomicPtr#695

Closed
ibraheemdev wants to merge 3 commits intosalsa-rs:masterfrom
ibraheemdev:no-arc-swap
Closed

Replace arc-swap with manual AtomicPtr#695
ibraheemdev wants to merge 3 commits intosalsa-rs:masterfrom
ibraheemdev:no-arc-swap

Conversation

@ibraheemdev
Copy link
Member

@ibraheemdev ibraheemdev commented Feb 19, 2025

It seems that we don't actually need arc-swap for the memo table, because our deleted_entries queue 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 manual AtomicPtr object 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 MemoTable functions actually change with this PR, so I believe it is sound. The one catch is that we have to avoid returning ManuallyDrop<Box<T>> and instead work with NonNull until the allocation is actually freed and we can assert uniqueness, as Box is a noalias type (at least under the current rules).

I also played around with using boxcar::Vec instead 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.

@netlify
Copy link

netlify bot commented Feb 19, 2025

Deploy Preview for salsa-rs canceled.

Name Link
🔨 Latest commit 0fff28f
🔍 Latest deploy log https://app.netlify.com/sites/salsa-rs/deploys/67b5fb7d9a198a0008cba0ed

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 19, 2025

CodSpeed Performance Report

Merging #695 will improve performances by 12.42%

Comparing ibraheemdev:no-arc-swap (0fff28f) with master (c86a457)

Summary

⚡ 3 improvements
✅ 6 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
accumulator 4.1 ms 3.7 ms +11.3%
amortized[Input] 4 µs 3.6 µs +11.61%
amortized[InternedInput] 4 µs 3.6 µs +12.42%

@MichaReiser
Copy link
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.

Copy link
Member

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is correct. r=me

@MichaReiser
Copy link
Contributor

@ibraheemdev this needs a rebase. Happy to merge once that's done.

@davidbarsky
Copy link
Contributor

Closing this PR as it landed in #737.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants