From 02167caf60ac9b40e0f9f8ceccbba4abb5fabec9 Mon Sep 17 00:00:00 2001 From: atlas Date: Sun, 19 Jul 2026 15:25:58 +0200 Subject: [PATCH] refactor(#2500): skip the empty acquire for fully re-entrant nodes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- hive-jobq/src/scheduler.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/hive-jobq/src/scheduler.rs b/hive-jobq/src/scheduler.rs index b6fc8883..0fe62cd4 100644 --- a/hive-jobq/src/scheduler.rs +++ b/hive-jobq/src/scheduler.rs @@ -125,12 +125,17 @@ impl Scheduler { owned_reqs.push((name, count)); } } - // Owned units are all-or-nothing; borrow slots were all confirmed free - // above, so this is the only fallible step. Nothing mutated until here. - let Some(guard) = self.resources.acquire(owned_reqs) else { - return false; - }; - self.owned.entry(id).or_default().push(guard); + // Owned units (if any) are all-or-nothing; borrow slots were all + // confirmed free above, so acquiring them is the only fallible step. + // Nothing is mutated until here. Skip the acquire + guard entirely when + // every dep was re-entrant (no owned units): an empty guard would just + // be a no-op `Drop` plus a wasted `owned` entry. + 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 { self.borrow_slots.insert(slot, id); }