Severity: MED — small allocations in reachable? (which is on the add_edge hot path).
Where:
What:
stack = fetch_set(adj, start).to_a allocates an Array; stack.concat(fetch_set(adj, current).to_a) allocates another per loop iteration.
walk is the body of reachable? / ancestors / descendants. reachable? is the cycle-detection walk on the add_edge path.
Suggested fix:
Iterate the Set and push: fetch_set(adj, start).each { |x| stack << x } and the same in the loop. Combined with the Loader fix (use insert_edge), shaves real loader latency.
Filed from a multi-agent review (DRY / efficiency / bug). Behavior change is out of scope; suggested fixes are refactors only.
Severity: MED — small allocations in
reachable?(which is on theadd_edgehot path).Where:
lib/dag/graph.rb:614-628What:
stack = fetch_set(adj, start).to_aallocates an Array;stack.concat(fetch_set(adj, current).to_a)allocates another per loop iteration.walkis the body ofreachable?/ancestors/descendants.reachable?is the cycle-detection walk on theadd_edgepath.Suggested fix:
Iterate the Set and push:
fetch_set(adj, start).each { |x| stack << x }and the same in the loop. Combined with the Loader fix (useinsert_edge), shaves real loader latency.Filed from a multi-agent review (DRY / efficiency / bug). Behavior change is out of scope; suggested fixes are refactors only.