GitNexus/gitnexus/bench/http-route-symbols/RESULTS.md
Abhinav Pandey d6917308d5
perf(group): load route handler symbols for many files in one query (#3929)
* perf(group): load route handler symbols for many files in one query

What

- Add CONTAINING_FILES_QUERY: CONTAINING_QUERY's three-label UNION ALL
  with `sym.filePath IN $filePaths`, at most 500 files per query.
- The HTTP route extractor's per-file symbol cache now takes a list of
  files it should expect to be asked for. The graph provider pass names
  every file whose HANDLES_ROUTE row carries a handlerSymbolId; after the
  project scans, the files with project-scan detections are named too.
  The first cache miss loads all of them, plus the file asked for, in one
  query and groups the rows by file. A file with no rows caches [], which
  is what its own query returns. A batch whose query fails caches nothing,
  so each of its files falls back to its own CONTAINING_QUERY. A file that
  was never named still gets its own CONTAINING_QUERY, as before.
- CONTAINING_QUERY and CONTAINING_FILES_QUERY are exported so an
  integration test can run both against a real LadybugDB.

The batch has no ORDER BY, the same as CONTAINING_QUERY. Rows are grouped
by file in arrival order, so each file keeps the row order its own query
gives (Function, then Method, then CodeElement rows, each in scan order).
resolveSymbolByName and resolveContainingSymbol depend on that order to
break ties, so it is left as it was.

Why

`filePath` is not indexed, so each CONTAINING_QUERY scans the Function,
Method and CodeElement tables to find the rows of one file, and the
extractor issued one of these for every file it resolved a symbol in.

Results

18 route fixtures from gitnexus/test/fixtures, each analyzed once, with
the extractor of origin/main and of this branch run alternately (one
warm-up, then 3 runs each). Both builds were given the same HANDLES_ROUTE
and FETCHES rows, so they saw the same input order.
- Output: byte-identical in all 6 runs for every repository (87 HTTP
  contracts).
- Symbol queries: 41 per-file -> 11 batched + 7 per-file.
- Median extract time summed over the 18 repositories: 217.8 ms ->
  169.4 ms, of which time in symbol queries 85.4 ms -> 39.5 ms.
- `gitnexus group sync` over a group of the 18 repositories: 108
  contracts and 8 cross-links in every run, and the sorted contracts.json
  is identical across 3 runs per build. The unsorted file differs between
  two runs of origin/main as well, because HANDLES_ROUTE_QUERY and
  FETCHES_QUERY have no ORDER BY.

This repository's own graph at 5c7da84f (3,565 files, 124,815 nodes, 118 HTTP
contracts):
- Symbol queries: 22 per-file -> 2 batched (8 files) + 14 per-file,
  covering the same 22 files and returning the same 681 rows.
- Replaying each build's recorded symbol queries, 7 alternating runs:
  median 197.3 ms -> 145.7 ms.
- The remaining 14 per-file queries are files reached through FETCHES
  rows, which are not named in advance.

Testing

- Unit (http-route-extractor.test.ts): one handler-file batch and no
  per-file queries; a file never named gets its own query; a failing
  batch falls back to one query per file with identical contracts; a file
  the batch has no rows for caches [] with no further query; batched and
  per-file runs resolve the same symbols, including an equal-span tie
  that only row order decides.
- Express stubs that matched on $filePath also answer $filePaths, and the
  failed-lookup test in http-route-graph-method.test.ts now expects the
  failing batch followed by one per-file query, still with no retry per
  route.
- Integration (http-route-symbol-batch.test.ts): real pipeline and
  LadybugDB; for every file, the batch returns exactly that file's
  CONTAINING_QUERY rows in the same order, and the extractor gives the
  same contracts with and without the batch, in fewer queries.
- With the source change reverted, 8 of these tests fail.
- tsc --noEmit; vitest on test/unit/group, test/integration/group and
  the route integration tests: 83 files, 1462 tests passed.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* perf(group): enforce linear symbol loading

Bound selective lookups, reuse one symbol snapshot for larger workloads,
and index handler IDs per file. Add a native scaling gate with exact
contract checks and before/after evidence.

Refs #3929

* perf(group): load named symbol files with one hash-join query

Above 500 files the loader switched to a scan that returned every
symbol row of the repository. Row transfer costs far more per row than
the scan, so on a 120,000-symbol database 501 handler files took 9.3 s
against 0.42 s for the 500-file IN batches before it and 6.3 s for one
query per file, and files discovered late paid 500 per-file queries and
then the scan.

Replace both the capped IN batches and the complete scan with one
UNWIND join per group of named files. The engine plans it as a hash
join: one scan per table whatever the length of the list, and only the
named files' rows come back. Every pass now names its files first (all
route files, then every scanned file with a detection), so a healthy
extraction issues two symbol queries. Same shapes after the change:
501 handler files 0.24 s, 501 late files 0.48 s (was 16 s), identical
contracts.

Sort each file's rows on node table and scan offset when they enter the
cache. On a multi-thread connection the engine returns a file's rows in
an order that changes between calls, so the first-match resolvers could
pick a different symbol from run to run; the three load paths now give
one order by construction.

Bench: every fixture holds as many unrequested symbols again and each
run asserts the queries returned exactly the requested files' rows;
returned rows join the gated metrics; median averages the two middle
values for an even sample count. The integration test compares row sets
for every file, adds a mixed-label file with an equal-span tie, asserts
exact query counts, and is registered in the lbug-db project and the
cross-platform list.

Refs #3929

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* docs(bench): re-measure the route symbol gate at the join loader

Regenerate the committed evidence with the harness of e6fa28fcb from
clean checkouts: baseline 5340562f5 (500-file IN batches) fails the
gate on scanned tuples (9.00) and handler-ID reads (15.94); candidate
e6fa28fcb passes every comparison, with scanned tuples, returned rows
and ID reads at exactly 1.00. RESULTS.md names both commits, records
that the complete-scan revision 2ebbdd79d fails the returned-rows check
at N=1,024, and drops the wording that described 5340562f5 as the PR
head.

Refs #3929

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: Gergő Magyar <gergomagyar@icloud.com>
Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com>
2026-11-14 22:06:10 +00:00

6.2 KiB
Raw Permalink Blame History

PR #3929 scaling results

Measured on 2026-11-14, Linux, Node v22.23.3, 12th Gen Intel(R) Core(TM) i9-12900K, one LadybugDB execution thread and a 128 MiB buffer pool. This was a shared development host (load average 6.0 at the start of the baseline run and 2.9 at the start of the candidate run). Each input size used a fresh process, two warmups and seven measured invocations.

The baseline is commit 5340562f5c0b1475f796ddfaf4abe4d780118ed2: the PR's first change, which loads expected files with filePath IN $filePaths, 500 files per query. The candidate is commit e6fa28fcba582d076e62b9c19c20c00dd1d8afcd: one join query per group of named files, every pass naming its files first, per-file ID maps and a fixed per-file row order. Both were measured from clean checkouts with the harness of the candidate commit (--root selects the checkout under test):

  • Baseline extractor: 18d3ab554d7191ac47ef6570c126b3ac65a483edf3578b13257838a1bcd1bd72
  • Candidate extractor: 288fc2c3371e47e3acbdf7ba21e36ee227ffd915331fa8dbdbaeb5ed5c81b9a8
  • Shared harness: 2d6b525e24db45cf04a6b3f7c927416af520a0c5447e9352e0b0a54cfaf95c9d

Both runs used identical harness, lockfile and scaling-guard hashes. All nine full-contract fingerprints agree. Raw samples, native PROFILE plans and gates are in baseline.json and candidate.json. See README.md for commands, measurement boundaries and the workload definitions.

Verdict

The baseline fails the 1.5 normalized-growth gate. For a 16× input increase:

Cost Baseline growth Candidate growth Baseline normalized factor Candidate factor
Spread-file scanned tuples 144× 16× 9.00 1.00
Dense-file handler-ID reads 255.07× 16× 15.94 1.00

Batching 500 files reduces query count but rescans all symbol tables per batch. Separately, searching a file's symbol array for every handler repeats work as both the handler count and file size grow. Timings alone missed both problems: the baseline's wall-time factors stayed under 1.5 on these inputs.

The candidate passes every adjacent-size and full-span comparison for wall time, CPU, endpoint heap, endpoint RSS, process maximum RSS, scanned tuples, returned rows and handler-ID reads. Its worst normalized wall-time factor is 1.0865; its worst CPU factor is 1.0127. The work counters grow exactly with input size in the spread and dense cases. Sparse requests return the six rows of the requested file at every size.

An intermediate revision (2ebbdd79d) replaced the 500-file batches above 500 files with one scan of every symbol row. It kept scanned tuples linear, and returned the rows of every file in the repository. This harness now holds as many unrequested symbols as requested ones and checks the returned rows, and that revision fails it at the first size above 500 files (spread, N=1,024: 12,288 rows returned for 6,144 requested). On a 120,000-symbol on-disk database with 501 handler files, a separate probe measured 9.3 s for that revision, 0.42 s for the baseline, 6.3 s for one query per file and 0.24 s for the candidate (one thread, medians of three, same shared host).

All measured sizes

Times are per-extraction medians. Revisions ran sequentially, not as interleaved pairs, so these timings illustrate this host's runs rather than establish a portable speedup or a strict cross-revision regression bound.

Arm N Baseline ms Candidate ms Baseline max RSS MiB Candidate max RSS MiB
Spread 256 168.61 110.09 210.58 217.22
Spread 1,024 548.67 465.07 225.00 235.40
Spread 4,096 2,650.61 1,758.12 264.44 327.47
Dense 256 121.43 108.19 211.44 220.93
Dense 1,024 486.06 470.17 222.93 227.79
Dense 4,096 2,122.60 1,426.29 265.58 290.84
Sparse 256 10.22 9.63 205.91 214.51
Sparse 1,024 7.22 9.43 206.59 221.22
Sparse 4,096 9.99 12.18 234.39 263.00

At N=4,096 the spread workload's native scanned tuples drop from 442,368 to 49,152, and the dense workload's ID reads drop from 16,781,312 to 24,576.

The candidate's process maximum RSS is higher at the largest sizes (spread 327 against 264 MiB, dense 291 against 266 MiB at N=4,096). Its normalized growth factors for the three memory measures stay at 0.35 or below.

One query returns every named file's rows, so its duration and memory grow with the rows requested; a batch that fails or exceeds the pool's query timeout falls back to one query per file. Neither these checks nor the implementation claim linearity for all source scanning, name resolution, or failure paths in complete group sync. The fixtures name every route file through the graph; files found only by the source scan are covered by the unit tests, not by this harness.

Validation

  • The baseline completed all nine cases and failed the work-scaling gate; the candidate completed the same cases and passed.
  • Affected group unit and integration suites, the native symbol-query integration test, the route round-trip integration tests and the test-list guards: 88 files, 1,570 tests passed at the candidate commit.
  • Production and test TypeScript checks: passed. Prettier: passed. ESLint: no errors.
  • GitNexus change analysis at the candidate commit: 10 files, 49 symbols, no affected execution flow, low risk. Upstream impact of HttpRouteExtractor reaches group sync, auto-sync and the MCP group_sync tool.

CI runs the complete gate in the existing serial benchmark job and uploads its JSON even when the gate fails. These results describe local validation.