Skip to content

Commit

Permalink
Merge pull request #622 from MichaReiser/small-accumulator-perf
Browse files Browse the repository at this point in the history
Approximate sizes of `stack` and `visisted` when collecting accumulated values
  • Loading branch information
MichaReiser authored Dec 6, 2024
2 parents e68679b + 5314d4c commit c2a6d62
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/function/accumulated.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use super::{Configuration, IngredientImpl};
use crate::zalsa_local::QueryOrigin;
use crate::{
accumulator::{self, accumulated_map::AccumulatedMap},
hash::FxHashSet,
zalsa::ZalsaDatabase,
AsDynDatabase, DatabaseKeyIndex, Id,
};

use super::{Configuration, IngredientImpl};

impl<C> IngredientImpl<C>
where
C: Configuration,
Expand Down Expand Up @@ -69,15 +69,25 @@ where
// output vector, we want to push in execution order, so reverse order to
// ensure the first child that was executed will be the first child popped
// from the stack.
let origin = zalsa
let Some(origin) = zalsa
.lookup_ingredient(k.ingredient_index)
.origin(db, k.key_index);
let inputs = origin.iter().flat_map(|origin| origin.inputs());
.origin(db, k.key_index)
else {
continue;
};

if let QueryOrigin::Derived(edges) | QueryOrigin::DerivedUntracked(edges) = &origin {
stack.reserve(edges.input_outputs.len());
}

stack.extend(
inputs
.flat_map(|input| TryInto::<DatabaseKeyIndex>::try_into(input).into_iter())
origin
.inputs()
.filter_map(|input| TryInto::<DatabaseKeyIndex>::try_into(input).ok())
.rev(),
);

visited.reserve(stack.len());
}

output
Expand Down

0 comments on commit c2a6d62

Please sign in to comment.