Merge pull request #567 from MichaReiser/reduce-set-cloning
Some checks failed
Book / Book (push) Has been cancelled
Test / Test (false, beta) (push) Has been cancelled
Test / Test (false, stable) (push) Has been cancelled
Test / Test (true, nightly) (push) Has been cancelled
Test / Miri (push) Has been cancelled
Test / Benchmarks (push) Has been cancelled
Book / Deploy (push) Has been cancelled

Reduce cloning of sets in `ActiveQuery` and `QueryRevisions`
This commit is contained in:
Niko Matsakis 2024-08-28 09:37:11 +00:00 committed by GitHub
commit 884a30cf9d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 29 additions and 15 deletions

View file

@ -98,11 +98,11 @@ impl ActiveQuery {
self.input_outputs.contains(&(EdgeKind::Output, key))
}
pub(crate) fn revisions(&self) -> QueryRevisions {
pub(crate) fn into_revisions(self) -> QueryRevisions {
let input_outputs = if self.input_outputs.is_empty() {
EMPTY_DEPENDENCIES.clone()
} else {
self.input_outputs.iter().copied().collect()
self.input_outputs.into_iter().collect()
};
let edges = QueryEdges::new(input_outputs);
@ -117,7 +117,7 @@ impl ActiveQuery {
changed_at: self.changed_at,
origin,
durability: self.durability,
tracked_struct_ids: self.tracked_struct_ids.clone(),
tracked_struct_ids: self.tracked_struct_ids,
}
}

View file

@ -84,18 +84,13 @@ where
self.diff_outputs(db, database_key_index, old_memo, &revisions);
}
let value = self
.insert_memo(
zalsa,
id,
Memo::new(Some(value), revision_now, revisions.clone()),
)
.unwrap();
let stamped_value = revisions.stamped_value(value);
tracing::debug!("{database_key_index:?}: read_upgrade: result.revisions = {revisions:#?}");
stamped_value
let stamp_template = revisions.stamp_template();
let value = self
.insert_memo(zalsa, id, Memo::new(Some(value), revision_now, revisions))
.unwrap();
stamp_template.stamp(value)
}
}

View file

@ -356,6 +356,25 @@ pub(crate) struct QueryRevisions {
impl QueryRevisions {
pub(crate) fn stamped_value<V>(&self, value: V) -> StampedValue<V> {
self.stamp_template().stamp(value)
}
pub(crate) fn stamp_template(&self) -> StampTemplate {
StampTemplate {
durability: self.durability,
changed_at: self.changed_at,
}
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub(crate) struct StampTemplate {
durability: Durability,
changed_at: Revision,
}
impl StampTemplate {
pub(crate) fn stamp<V>(self, value: V) -> StampedValue<V> {
StampedValue {
value,
durability: self.durability,
@ -516,7 +535,7 @@ impl ActiveQueryGuard<'_> {
// If this frame were a cycle participant, it would have unwound.
assert!(popped_query.cycle.is_none());
popped_query.revisions()
popped_query.into_revisions()
}
/// If the active query is registered as a cycle participant, remove and