refactor(#2500): skip the empty acquire for fully re-entrant nodes

When every resource dep of a node re-enters an ancestor's lock, `owned_reqs`
is empty; the old code still called `acquire(vec![])` and stored a no-op
empty guard in `owned`. Gate the acquire + guard insertion on
`!owned_reqs.is_empty()` — one fewer `borrow_mut` + `HashMap` entry per
fully-re-entrant node in the settle loop. `node_owns` already treats a
missing `owned` entry as non-owning, so behaviour is unchanged.
This commit is contained in:
atlas 2026-07-19 15:25:58 +02:00 committed by mara
commit 02167caf60

View file

@ -125,12 +125,17 @@ impl<N, R: Clone + Eq + Hash> Scheduler<N, R> {
owned_reqs.push((name, count)); owned_reqs.push((name, count));
} }
} }
// Owned units are all-or-nothing; borrow slots were all confirmed free // Owned units (if any) are all-or-nothing; borrow slots were all
// above, so this is the only fallible step. Nothing mutated until here. // confirmed free above, so acquiring them is the only fallible step.
let Some(guard) = self.resources.acquire(owned_reqs) else { // Nothing is mutated until here. Skip the acquire + guard entirely when
return false; // every dep was re-entrant (no owned units): an empty guard would just
}; // be a no-op `Drop` plus a wasted `owned` entry.
self.owned.entry(id).or_default().push(guard); if !owned_reqs.is_empty() {
let Some(guard) = self.resources.acquire(owned_reqs) else {
return false;
};
self.owned.entry(id).or_default().push(guard);
}
for slot in borrows { for slot in borrows {
self.borrow_slots.insert(slot, id); self.borrow_slots.insert(slot, id);
} }