Skip to content

Flexible memo dropping behavior #874

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Veykril
Copy link
Member

@Veykril Veykril commented May 22, 2025

This allows users to opt-into receiving a channel receiver on storage creation that can be used to decide when and where to drop destructors of stale memo results.

Notably this does not yet handle LRU evictions, so those are still synchronous. Handling that is more complicated or will have to incur allocations so I am not yet sure how to best approach this. We could maybe consider a double buffer (triple buffer) approach for the deletion queues per ingredient instead and if those are exhausted fall back to blocking in case of too frequent revision bumps. That is something I will consider in a separate follow up PR though, for now this is ready for a review.

Note that the perf changes are noise due to allocation order differences.

Copy link

netlify bot commented May 22, 2025

Deploy Preview for salsa-rs canceled.

Name Link
🔨 Latest commit afa442f
🔍 Latest deploy log https://app.netlify.com/projects/salsa-rs/deploys/688f1e476edca3000816c27c

@Veykril Veykril force-pushed the veykril/push-proytsnlytqr branch 2 times, most recently from 8237471 to ce1baa4 Compare May 22, 2025 09:58
Copy link

codspeed-hq bot commented May 22, 2025

CodSpeed Performance Report

Merging #874 will not alter performance

Comparing Veykril:veykril/push-proytsnlytqr (afa442f) with master (c3f86b8)

Summary

✅ 12 untouched benchmarks

@Veykril Veykril force-pushed the veykril/push-proytsnlytqr branch from ce1baa4 to c715adb Compare May 22, 2025 10:04
@Veykril

This comment was marked as outdated.

@Veykril Veykril force-pushed the veykril/push-proytsnlytqr branch 2 times, most recently from 7be2574 to bcca0a3 Compare May 24, 2025 07:37

/// An untyped memo that can only be dropped.
#[derive(Debug)]
pub struct MemoDrop(NonNull<DummyMemo>, unsafe fn(NonNull<DummyMemo>));
Copy link
Contributor

Choose a reason for hiding this comment

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

Three things:

  1. I didn't know it was legal to write unsafe fn(NonNull<DummyMemo>). I'm guessing that if you pass it a safe closure, this will fail to compile?
  2. Can you make these named fields instead of tuple structs?
  3. I really think this should be tested with Shuttle. if you're okay with me pushing to your branch, i can do that?

Copy link
Member Author

@Veykril Veykril Aug 2, 2025

Choose a reason for hiding this comment

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

I didn't know it was legal to write unsafe fn(NonNull). I'm guessing that if you pass it a safe closure, this will fail to compile?

No, safe functions/closures can be coerced to unsafe ones just fine. After all calling a safe function in an unsafe context isn't problematic. Only the other direction won't work for obvious reasons.

The other two questions won't be relevant anymore once im finished writing out the new approach

@Veykril Veykril force-pushed the veykril/push-proytsnlytqr branch from 01799e6 to 66c99be Compare June 17, 2025 09:43
@Veykril Veykril force-pushed the veykril/push-proytsnlytqr branch 5 times, most recently from 361410b to d89e9ae Compare August 2, 2025 12:46
@Veykril Veykril changed the title Move memo dropping off to another thread Flexible memo dropping behavior Aug 2, 2025
@Veykril
Copy link
Member Author

Veykril commented Aug 2, 2025

Okay, new approach. The user is now in charge of things. We now have two dropping modes, synchronous (what we currently have) and channel based, where the user will receive a receiver on storage construction that they can poll to drop things as they like.

@Veykril Veykril force-pushed the veykril/push-proytsnlytqr branch 2 times, most recently from ba28ff2 to 67280df Compare August 2, 2025 13:02
@Veykril
Copy link
Member Author

Veykril commented Aug 2, 2025

So, delaying the LRU clears is actually a bit more difficult and as it turns out, my previous approach was even unsound. We need to remove the values immediately, as otherwise we might be racing with computations of the next revision. That is a bit unfortunate though, as the values are not necessarily allocated and so we can't just take the pointer as an opaque droppable thing. That leaves two options, allocate LRU'd values that are to be dropped elsewhere individually, or use a (paged) arena allocator and move the value into that. Neither approach seems nice to me ...

@Veykril Veykril force-pushed the veykril/push-proytsnlytqr branch from 67280df to 053d779 Compare August 2, 2025 13:23
@Veykril Veykril marked this pull request as ready for review August 2, 2025 13:23
@Veykril Veykril force-pushed the veykril/push-proytsnlytqr branch from 053d779 to d5b58fb Compare August 3, 2025 05:32
@Veykril Veykril force-pushed the veykril/push-proytsnlytqr branch from d5b58fb to afa442f Compare August 3, 2025 08:31
Copy link
Contributor

@davidbarsky davidbarsky left a comment

Choose a reason for hiding this comment

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

LGTM, but I think I'd prefer someone from Astral to also approve this—conflict of interest and all.

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.

3 participants