Skip to content

perf: replace unbounded spreads and quadratic layout lookups - #21

Merged
bwin merged 2 commits into
devfrom
perf/layout-bounds-indexes
Nov 3, 2026
Merged

bwin merged 2 commits into
devfrom
perf/layout-bounds-indexes

Conversation

@bwin

@bwin bwin commented Nov 3, 2026 •

Copy link
Copy Markdown
Owner

Summary

Fixes CONFIRMED-FINDINGS.md items 5 and 6 (grouped because both are layout-scaling changes that must not alter geometry).

  • src/layout.ts: adds linear maxOf/minOf helpers and removes argument spreads over links, nodes, stages, routes and labels. Precomputes node input indexes and groups links by from/to once so port construction no longer runs indexOf/filter per node. Port groups are copied before sorting, preserving input order.
  • src/paths.ts: describe() computes length and x/y bounds in one linear pass instead of four spreads.
  • tests/paths.test.ts: regression calls describe() with 200,000 points and checks bounds without RangeError; the old implementation throws RangeError on this input.
  • CHANGELOG.md: one scoped [Unreleased] / Fixed entry.

Geometry equivalence

All five benchmark scene hashes match dev exactly before and after:

Case Scene hash Crossings
stress-100-300 c4c086c4…557a99 1758
allocations-desktop 64598e2b…a668d 7
allocations-mobile ee1de1c7…68780 8
four-sided bea2886d…b7e2 19
wrapped-fan edbd6da6…f3062 0

The reviewer also compared 301 additional scenes (demo graphs, widths, minLinkWidth, edge nodes, empty/zero-link graphs) with zero mismatches.

Performance

Raw full-benchmark timings were noisy on the shared host and are not a reliable before/after comparison. The controlled same-process alternating stress A/B is the meaningful evidence:

  • Reviewer: dev 105.29 ms vs PR 99.75 ms, −5.3%, across 20 alternating pairs.
  • Coding agent: two alternating runs, −6.4% each.

Verification

  • npm run format — passed
  • npm run typecheck — passed
  • npm run lint — passed
  • npm test — 153 tests passed
  • npm run build — passed
  • npm run stress — identical scene hash and crossings
  • npm run benchmark — all five fixture hashes matched before/after
  • Reviewer ran differential geometry checks over 301 scenes with zero mismatches

Notes

Browser tests were not run to avoid the shared Playwright port. No geometry, ordering or diagnostics were intentionally changed. Some other quadratic-looking scans remain outside the specific item-6 lookups; the changelog is scoped accordingly.

bwin added 2 commits November 3, 2026 02:31
Compute geometry bounds with linear helpers instead of argument spreads, and index node positions plus link endpoints once per layout. Scene geometry and diagnostics remain unchanged.
Describe the removed argument spreads and the precomputed node/link indexes precisely, and note the helper empty-input fallbacks.
@bwin
bwin merged commit 9eaf23d 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