Files
codegraph/__tests__
Aaron QueenandClaude Opus 5.5 4eb8c2a5f2 perf(synthesis): line numbers from a newline index, not a split per match
Two quadratic idioms in callback-synthesizer.ts. Twelve passes computed
each match's line as `safe.slice(0, m.index).split('\n').length`, which
copies and splits the file's prefix for every match, and `sliceLines`
split the whole file again for every node a pass looked at (7 callers,
one per node of the same file in a row).

The twelve sites now call `lineOf(src, idx)`, which keeps the newline
index of the last text (built with synth-utils' `makeLineAt`, which
counts the newlines strictly before `idx`, exactly like the old idiom),
and `sliceLines` keeps the last file's lines.

Ours on top: `releaseLineCaches()` at the end of synthesizeCallbackEdges.
The pool workers' copies go with the workers (pool.destroy() after
synthesis), but a sync runs synthesis on the main thread, so a long-lived
MCP server or `watch` kept the last file's text, its lines and its newline
index until the next synthesis. And a celery test with two files of the
same length scanned in a row, which fails if the line index is reused
across texts (checked by keying the cache on length).

Validation, main 81559dcc vs this:
- dump-graph of every table (nodes, edges with metadata, refs, files)
  byte-identical on pretix c9f7bf86 (79,452 edges), trezor-suite
  505aece5 (493,138 edges), excalidraw d3a9c2a1 (46 react-render),
  vben 61c07936 (128 pinia-store), gin and eShopOnWeb (Go and C#
  controls with gin-middleware-chain and mediatr-dispatch edges).
- The pass outputs are identical, edge for edge and in the same order,
  when each touched pass runs alone over the same index. Their CPU, the
  median of 3 runs after a warm-up: pretix 1,018 -> 845 ms (React render
  204 -> 32 ms, field channels 235 -> 172 ms), trezor-suite 7,686 vs
  7,841 ms (noise; its Pinia and Vuex scans dominate and are untouched).
- Whole-index CPU on pretix, median of 3 interleaved: 99.8 vs 99.4 s.
  No CHANGELOG entry: the gain is per pass, not visible per index; the
  PR's bullet sat in the released 1.6.1 section and is dropped.

Original PR #1985 by @bompus.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 16:45:47 +00:00
..