perf(resolve): faster small-project index; ASCII fast path for minified one-line files
Indexing Alamofire's resolution step takes a median 0.93 s instead of 1.25 s, 26% less (profiling runs, 5,614 nodes and 13,673 edges either way). The README had listed gin's and Alamofire's slower full index as an unexplained cost; this removes two causes.
What changed
js_unit_to_byte(kernel,resolve/names.rs) converts a UTF-16 column to a byte offset. It walked the line from its start on every call. Alamofire'sdocs/js/jquery.min.jsis one 87 KB line, and the resolver called the helper dozens of times per reference in it, so those 1,004 references cost about 380 µs each, 40% of Alamofire's resolution time. It now returns at once when the bytes before the offset are ASCII, and otherwise walks as before. A unit test compares it to the old walk at every offset on ASCII, accented, astral and U+2028 strings.- A kernel over the live database either loads the node table or answers lookups by query. The cut-off was 15,000 pending references, measured on ktor. The load costs per node and the queries per ref, so the cut-off now also requires fewer than 0.3 references per node (ktor: 49.7k nodes, crossover near 16k refs). gin (3.1k nodes, 13.6k refs) loads the table, about 60 ms of its one-second index; a one-file sync still queries. A test pins the three cases.
- Removes the "Slower full index on small projects" open question and rewrites the README bullet that linked it.
Measured (alternating runs, same host, load 3 to 5, so figures are screening evidence, not benchmark results; the benchmark has not been re-run)
| Corpus, Node 24 | Before | After | Change |
|---|---|---|---|
| Alamofire resolution step (median of 4) | 1,252 ms (1,188–1,330) | 929 ms (900–1,014) | 26% less |
| Alamofire whole index (median of 4) | 2.07 s (1.96–2.21) | 1.70 s (1.66–2.03) | 18% less |
| gin whole index | 1.06–1.20 s | 1.06–1.17 s | no clear change |
| discourse whole index | 23.9–24.7 s | 23.0–23.7 s | no clear change |
In these runs gin was not slower than upstream (fork 1.06–1.17 s, upstream 1.27–1.29 s). A busy host hurts upstream's parallel workers more than the fork's single thread, so only the quiet-host re-run settles gin.
Checks
- The edge list (source, target, kind, line, column, provenance) is byte-identical before and after on gin, Alamofire and discourse.
- Full vitest suite on Node 24.21: 696 files, 8,905 passed, 39 skipped, no worker crash in stderr.
__tests__/readme-sync.test.tspasses after the README edit. - The kernel unit test fails on the old walk's results if the fast path is wrong; the lookup test fails on the old 15,000-only rule (gin would query).
Related: #92 and #115 removed per-reference rescans in the walkers; this is the resolver's own column helper, which they did not touch.
README rows checked: "What it costs", Slower full index on small projects (rewritten); the Bun bullet, database-size and fewer-edges bullets and the measured-results tables are unchanged because nothing here moves them. Open questions entry removed.
Summary by CodeRabbit
- Bug Fixes
- Improved reference-resolution performance for large reference sets and minified JavaScript files, reducing slowdowns in full-index operations on smaller projects.
- Documentation
- Updated performance notes with the identified causes and benchmark results.