mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-07 11:03:15 +00:00
perf(engine): index variables once when following a library's alias chains (#1968)
* perf(engine): index variables once when following a library's alias chains * address review: return before indexing variables for an empty seed set
This commit is contained in:
1 parent
898a08b0ce
commit
5f022aa8a9
1 file changed
+9
-1
@@ -277,8 +277,16 @@ pub fn default_selection(doc: &Document, prev: Option<&LibraryManifest>) -> Sele
|
||||
fn alias_closure(vars: &Variables, seeds: impl IntoIterator<Item = VariableId>) -> BTreeSet<VariableId> {
|
||||
let mut out = BTreeSet::new();
|
||||
let mut stack: Vec<VariableId> = seeds.into_iter().collect();
|
||||
if stack.is_empty() {
|
||||
return out;
|
||||
}
|
||||
// Indexed once (the first of equal ids, as `get_by_id` finds it): a scan per step is quadratic on a long alias chain.
|
||||
let mut by_id = std::collections::HashMap::new();
|
||||
for v in &vars.variables {
|
||||
by_id.entry(v.id.as_str()).or_insert(v);
|
||||
}
|
||||
while let Some(cur) = stack.pop() {
|
||||
let Some(v) = vars.get_by_id(&cur) else { continue };
|
||||
let Some(v) = by_id.get(cur.as_str()).copied() else { continue };
|
||||
if out.len() >= MAX_ASSETS || !out.insert(v.id.clone()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user