mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-02-02 09:46:06 +00:00
Merge #371
371: Ported LRU improvements from old salsa to salsa 2022 r=nikomatsakis a=OLUWAMUYIWA ## What? In handling evictions from the LRU, I replaced the `delete_memo` with `evict` in the while keeping the `delete_memo` intact. ## How? This mechanism was already implemented in old `salsa `. I only had to port it. Fixes: #365 Co-authored-by: OLUWAMUYIWA <onigbindemy@gmail.com> Co-authored-by: Onigbinde Oluwamuyiwa Elijah <onigbindemy@gmail.com> Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
This commit is contained in:
commit
5ce4662b81
2 changed files with 36 additions and 23 deletions
|
@ -1,10 +1,6 @@
|
|||
use arc_swap::Guard;
|
||||
|
||||
use crate::{
|
||||
database::AsSalsaDatabase,
|
||||
runtime::{local_state::QueryOrigin, StampedValue},
|
||||
AsId, Database,
|
||||
};
|
||||
use crate::{database::AsSalsaDatabase, runtime::StampedValue, AsId, Database};
|
||||
|
||||
use super::{Configuration, DynDb, FunctionIngredient};
|
||||
|
||||
|
@ -94,23 +90,6 @@ where
|
|||
}
|
||||
|
||||
fn evict(&self, key: C::Key) {
|
||||
if let Some(memo) = self.memo_map.get(key) {
|
||||
match memo.revisions.origin {
|
||||
QueryOrigin::Assigned(_)
|
||||
| QueryOrigin::DerivedUntracked(_)
|
||||
| QueryOrigin::BaseInput
|
||||
| QueryOrigin::Field => {
|
||||
// Careful: Cannot evict memos whose values were
|
||||
// assigned as output of another query
|
||||
// or those with untracked inputs
|
||||
// as their values cannot be reconstructed.
|
||||
return;
|
||||
}
|
||||
|
||||
QueryOrigin::Derived(_) => {
|
||||
self.delete_memo(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
self.memo_map.evict(key);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,40 @@ impl<K: AsId, V> MemoMap<K, V> {
|
|||
pub(super) fn get(&self, key: K) -> Option<Guard<Arc<Memo<V>>>> {
|
||||
self.map.get(&key).map(|v| v.load())
|
||||
}
|
||||
|
||||
/// Evicts the existing memo for the given key, replacing it
|
||||
/// with an equivalent memo that has no value. If the memo is untracked, BaseInput,
|
||||
/// or has values assigned as output of another query, this has no effect.
|
||||
pub(super) fn evict(&self, key: K) {
|
||||
use crate::runtime::local_state::QueryOrigin;
|
||||
use dashmap::mapref::entry::Entry::*;
|
||||
|
||||
if let Occupied(entry) = self.map.entry(key) {
|
||||
let memo = entry.get().load();
|
||||
match memo.revisions.origin {
|
||||
QueryOrigin::Assigned(_)
|
||||
| QueryOrigin::DerivedUntracked(_)
|
||||
| QueryOrigin::BaseInput
|
||||
| QueryOrigin::Field => {
|
||||
// Careful: Cannot evict memos whose values were
|
||||
// assigned as output of another query
|
||||
// or those with untracked inputs
|
||||
// as their values cannot be reconstructed.
|
||||
return;
|
||||
}
|
||||
|
||||
QueryOrigin::Derived(_) => {
|
||||
let memo_evicted = Arc::new(Memo::new(
|
||||
None::<V>,
|
||||
memo.verified_at.load(),
|
||||
memo.revisions.clone(),
|
||||
));
|
||||
|
||||
entry.get().store(memo_evicted);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
Loading…
Reference in a new issue