Skip to content

Speed up obstacle detour searches; add collision-heavy benchmark - #14

Merged
bwin merged 6 commits into
devfrom
claude/repo-review-audit-5c1539
Nov 3, 2026
Merged

bwin merged 6 commits into
devfrom
claude/repo-review-audit-5c1539

Conversation

@bwin

@bwin bwin commented Nov 3, 2026 •

Copy link
Copy Markdown
Owner

What

  • Adds an obstacle-8x12 benchmark case (fixtures/stress.ts, scripts/benchmark-layout.mjs): eight columns of twelve long-titled nodes, about a third of the links skipping a column. The stress graph never leaves a route colliding, so it never reaches the detour search or the width-retry loop; this one does.
  • Speeds up avoidObstacles: each visibility-grid edge is tested only against boxes whose open row/column range contains it (an axis-aligned segment cannot hit any other box), and search state moves from Maps to typed arrays. Search budgets, diagnostics and tie-breaking are unchanged.
  • Adds direct avoidObstacles tests (it had none): seeded random fields including epsilon-sized boxes, plus a wall detour and a sealed case.
  • Adds an internal indexed parameter to avoidObstacles (default true, not exported from index.ts). With false it tests every box on every edge, and a test compares both modes with deepEqual on 200 seeded fields at two bend costs, including boxes within 1e-5 of a grid line and edges on the bounds. Trials where an endpoint lies inside a box (an early null) are not counted. Narrowing the index ranges fails this test; widening them (< to <=) cannot, because the collision check still rejects the extra boxes.
  • Pins the obstacleGraph() layout at width 1300 in tests/core.test.ts: scene width 1380, 377 crossings, 11 obstacle collisions, and at least one route with long exactly-horizontal and exactly-vertical runs (the detour signature; with avoidObstacles disabled this fixture has none). These values are meant to be updated after an intended routing change.
  • CHANGELOG and docs/performance.md updated.

Measured (Node, one machine, median of 3 runs)

Case Before After Scene hash
obstacle-8x12 4294 ms 1882 ms identical
stress-100-300 108 ms 104 ms identical
allocations-desktop / mobile, four-sided, wrapped-fan within noise within noise identical

typecheck, lint, format:check, npm test (156 tests on the head commit) pass; npm run build was last run before the final test-only commits. Not run: Playwright browser tests, verify:package, any browser rendering.

Not fixed here

Collision-heavy layouts remain slow. When a collision stays unresolved, layoutGraphSteps re-runs the whole layout at up to six widths and repeats the same detour searches each time (a 175-link variant took about 30 s before this change). Reducing that needs a change to the retry strategy rather than a pure optimization, so it is left for a separate decision. I also tried an exact reachability pre-check before the A* search; it did not help and is not included.

🤖 Generated with Claude Code

bwin and others added 6 commits November 3, 2026 01:34
The stress graph never leaves a route colliding with a bar or label, so it
skips the obstacle detour search and the width-retry loop. The new
obstacle-8x12 fixture (skip-column links, long titles) reaches both.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Index boxes by the grid rows and columns they span so each visibility-grid
edge is tested only against boxes that can block it, and keep search state in
typed arrays. All six benchmark scenes hash identically; the collision-heavy
case drops from about 4.3 s to 1.9 s. Add direct avoidObstacles tests.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
avoidObstacles takes an internal indexed flag; false tests every box on every
edge like the previous implementation. A seeded comparison over 200 fields
(epsilon boxes, near-touching neighbors, edges on the bounds and past them)
asserts identical routes and failures.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
An endpoint inside a box makes avoidObstacles return null before any
search, so those trials said nothing about the index. Skip them when
counting routed and unrouted outcomes, and note in the obstacle fixture
test that its pinned width and counts are meant to be updated after an
intended change.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@bwin
bwin merged commit 1c5b98a into dev Nov 3, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant