Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop memos on separate thread #660

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Veykril
Copy link
Member

@Veykril Veykril commented Jan 23, 2025

Stacked on top of #684

Notably this replaces the SeqQueue with the standard libraries mpsc which is also implemented as a seqmented list, this simplified things a bit. We might want to consider moving to a different channel implementation for performance reasons, be it crossbeam or something else.

Copy link

netlify bot commented Jan 23, 2025

Deploy Preview for salsa-rs canceled.

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

Copy link

codspeed-hq bot commented Jan 23, 2025

CodSpeed Performance Report

Merging #660 will not alter performance

Comparing Veykril:veykril/push-proytsnlytqr (ce4af66) with master (ff3ef18)

Summary

✅ 9 untouched benchmarks

@Veykril Veykril force-pushed the veykril/push-proytsnlytqr branch 3 times, most recently from 0bb7e71 to b740ae4 Compare January 27, 2025 08:18
@Veykril

This comment was marked as outdated.

@Veykril Veykril force-pushed the veykril/push-proytsnlytqr branch 2 times, most recently from fe9f121 to 50dc4c9 Compare January 31, 2025 10:00
@Veykril
Copy link
Member Author

Veykril commented Jan 31, 2025

I removed the LRU changes from this PR that were unrelated to the eviction changes, slimming down things a bit -> #664

@Veykril Veykril force-pushed the veykril/push-proytsnlytqr branch 2 times, most recently from 8522755 to d4aa44b Compare February 2, 2025 10:46
@Veykril Veykril changed the title Change LRU implementation to evict on new revision Evict LRU entries on new revision dropping memos on new thread Feb 5, 2025
@Veykril Veykril force-pushed the veykril/push-proytsnlytqr branch from d4aa44b to 1d5beef Compare February 6, 2025 12:58
@Veykril
Copy link
Member Author

Veykril commented Feb 6, 2025

Rebased on top of https://github.com/salsa-rs/salsa/pull/673/files which was split out of this PR given its a soundness fix

@Veykril Veykril force-pushed the veykril/push-proytsnlytqr branch 3 times, most recently from 5fdf4c8 to b37e8a9 Compare February 6, 2025 14:27
@MichaReiser
Copy link
Contributor

It's somewhat interesting that this changes the performance so significantly (maybe just noise?)

@Veykril
Copy link
Member Author

Veykril commented Feb 7, 2025

The numbers seem to be consistent (judging across my rebases), so I think this might just be due to more favorable code layout due to the changes, given the only thing that really changed for the benches is one branch being removed in a hot path (none of them bench eviction/lru/dropping of the database)

@Veykril
Copy link
Member Author

Veykril commented Feb 8, 2025

Two more things I'd like to follow up with, setting the LRU capacity should require mutable database access. There is no reason I can see as to why one should be allowed to change the limit mid computation. That change allows to remove an atomic load. The second thing is we should be able to trigger eviction without bumping the revision. I won't include those changes here though as there is already enough in this PR.

@Veykril Veykril force-pushed the veykril/push-proytsnlytqr branch from b37e8a9 to 164ed5a Compare February 11, 2025 10:56
@MichaReiser
Copy link
Contributor

The second thing is we should be able to trigger eviction without bumping the revision. I won't include those changes here though as there is already enough in this PR.

Makes sense. I assume that would still require a &mut db for soundness?

@Veykril
Copy link
Member Author

Veykril commented Feb 11, 2025

Yes, otherwise there might be some computation still going on that could be borrowing from a memo.

This change makes us LRU evict once a new revision starts, instead of at the very moment we reach the limit while computing tracked functions.
Notably the previous behavior was unsound as we were immediately clearing the value (without going through the delayed deletion buffer) while there could have been outstanding references.
Callers of these functions need to ensure that the value will be dropped when the revision ends
@Veykril Veykril force-pushed the veykril/push-proytsnlytqr branch from 164ed5a to ce4af66 Compare February 11, 2025 12:22
@Veykril Veykril changed the title Evict LRU entries on new revision dropping memos on new thread Evict LRU entries on new revision, dropping memos on new thread Feb 11, 2025
}

pub fn memo_drop_channel() -> (MemoDropSender, MemoDropReceiver) {
let (tx, rx) = std::sync::mpsc::channel();
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use a sync_channel instead to apply back pressure if the drop thread is getting overwhelmed?

What happens if a drop implementatio panics? I assume that leaves the entire database in a poisoned state because the drop thread is now "broken"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question regarding backpressure, unsure :)

What happens if a drop implementatio panics? I assume that leaves the entire database in a poisoned state because the drop thread is now "broken"?

Bad things. I have actually forgotten about destructors panicking, right now that will tear down the dropper thread and cause us to panic when evicting. It should be simple enough to workaround though with a catch_unwind, the bigger question then though becomes if its fine for us to silently eat panic payloads in destructors ...

@Veykril
Copy link
Member Author

Veykril commented Feb 12, 2025

I didn't split the PR into two as the second PR would be stacked either way but I've come to the realization yesterday that the dropping change has a lot of extra implications that need to be discussed more so I'll split this PR in two later

@Veykril Veykril changed the title Evict LRU entries on new revision, dropping memos on new thread Drop memos on separate thread Feb 12, 2025
@Veykril
Copy link
Member Author

Veykril commented Feb 12, 2025

Split out #684

@Veykril Veykril marked this pull request as draft February 12, 2025 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants