Fast path for linear deeply nested children

This commit is contained in:
novacrazy 2023-04-05 21:17:37 -05:00
parent af5b226e53
commit c0964c2b01

View file

@ -246,11 +246,11 @@ impl Runtime {
while let Some(iter) = stack.last_mut() { while let Some(iter) = stack.last_mut() {
let res = iter.with_iter_mut(|iter| { let res = iter.with_iter_mut(|iter| {
let Some(&child) = iter.next() else { let Some(mut child) = iter.next().copied() else {
return IterResult::Empty; return IterResult::Empty;
}; };
if let Some(node) = nodes.get_mut(child) { while let Some(node) = nodes.get_mut(child) {
if node.state == ReactiveNodeState::Check if node.state == ReactiveNodeState::Check
|| node.state == ReactiveNodeState::DirtyMarked || node.state == ReactiveNodeState::DirtyMarked
{ {
@ -266,11 +266,23 @@ impl Runtime {
); );
if let Some(children) = subscribers.get(child) { if let Some(children) = subscribers.get(child) {
return IterResult::NewIter(RefIter::new( let children = children.borrow();
children.borrow(),
|children| children.iter(), if !children.is_empty() {
)); // avoid going through an iterator in the simple psuedo-recursive case
if children.len() == 1 {
child = children[0];
continue;
}
return IterResult::NewIter(RefIter::new(
children,
|children| children.iter(),
));
}
} }
break;
} }
IterResult::Continue IterResult::Continue