Skip to content

Commit

Permalink
Merge pull request #567 from MichaReiser/reduce-set-cloning
Browse files Browse the repository at this point in the history
Reduce cloning of sets in `ActiveQuery` and `QueryRevisions`
  • Loading branch information
nikomatsakis authored Aug 28, 2024
2 parents f608ff8 + 74a4de4 commit 884a30c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/active_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
}
}

Expand Down
15 changes: 5 additions & 10 deletions src/function/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,13 @@ where
self.diff_outputs(db, database_key_index, old_memo, &revisions);
}

tracing::debug!("{database_key_index:?}: read_upgrade: result.revisions = {revisions:#?}");

let stamp_template = revisions.stamp_template();
let value = self
.insert_memo(
zalsa,
id,
Memo::new(Some(value), revision_now, revisions.clone()),
)
.insert_memo(zalsa, id, Memo::new(Some(value), revision_now, revisions))
.unwrap();

let stamped_value = revisions.stamped_value(value);

tracing::debug!("{database_key_index:?}: read_upgrade: result.revisions = {revisions:#?}");

stamped_value
stamp_template.stamp(value)
}
}
21 changes: 20 additions & 1 deletion src/zalsa_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 884a30c

Please sign in to comment.