Files
codegraph/__tests__
danusha2345andClaude Opus 5.5 d494e432ed fix(graph): a path search keeps one predecessor per node, so it stays linear
findPath's breadth-first search copied the whole path so far into every
queue entry and dequeued with Array.shift(). A long path cost time and heap
quadratic in its length, and a queued frontier held one copy per entry.

The search now keeps one predecessor per discovered node in a map, walks a
queue of ids with a head index, and builds the path once at the end. It keeps
the enqueue-once set from PR #2016. Targets are fetched once each even when
parallel edges point at the same node.

Red, green and A/B:
- Red on main: a 400-hop chain walks 81,001 array elements, against under
  4,000 now, and a fan-in batch asks for the same node twice. No timing in
  either test.
- Same paths: 400 seeded pairs each on excalidraw, gin and flask gave the same
  node and edge sequence on both arms (1,200 of 1,200).
- A 20,000-hop chain: 1,007 ms and 47 MB of heap on main, 30 ms and 13 MB here.

The test added in PR #2016 now counts node lookups per id instead of patching
Array.prototype.push, because the queue no longer holds objects with a path.
Its expectation is unchanged.

Original PR #1583 by @danusha2345.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 18:23:52 -05:00
..