kernel: perf batch A, O(1) UTF-16 columns and allocation removal across the walkers

Merged
BO
2mo ago
+416-224

The mechanical half of the kernel performance pass. Nothing here can change a verdict, so the byte-identical dump gate is the whole review.

The change that matters is the column service. Every walker measured a node's UTF-16 column by re-scanning the line prefix from the line start, twice per node and once per reference. That is linear in the line, so quadratic on a long line, and a minified bundle is one long line. textutil::Cols replaces it. An all-ASCII file reads columns straight off byte offsets. A non-ASCII file builds the UTF-16 prefix table once, on first use. The old col16 survives as the test oracle the new service is checked against.

The rest of the batch:

  • ids::node_id hex-encodes through a nibble table instead of sixteen format! calls per id.
  • Node and edge kind lookups are match tables instead of linear scans over the kind lists.
  • The {"valueRef":true} arena put is hoisted out of the value-reference loops in 13 walkers.
  • 29 collect()-then-iterate child walks became direct cursor iteration, and 21 &x.clone() reference pushes became &x.
  • The TypeScript walker's (name, line) String-keyed scoped-row and require() declarator lookups are line-keyed maps, and its line count comes from the column service instead of a third newline scan.
  • The doubled markdown_refs_from_string calls in the C/C++ and TypeScript walks are gone. A string node reached the second call on the same path with nothing emitted in between, so reference order is unchanged.
  • Java's Lombok owner test uses strip_prefix instead of formatting a qualified name per node per class. The C paren-conversion regex runs only on a (-led callee. The fn-pointer sweep keeps each keyword's next hit instead of re-searching both struct and union to end of file per match. Three from_utf8_lossy copies became from_utf8 moves. tree.rs reuses textutil::utf16_prefix.

Kernel-only extraction, one thread, every file the index holds, best of 3, baseline kernel built from e8ecd153 and loaded through CODEGRAPH_KERNEL_PATH:

corpusfilesbeforeafter
koel2,051484 ms461 ms
firefly-iii1,9541,484 ms951 ms
warp-drive1,631869 ms874 ms
halo2,251865 ms815 ms
pretix1,4172,762 ms2,263 ms
discourse15,56429,919 ms10,742 ms

At index level the parse loop is bound by the main thread's store, with six parse workers absorbing the walker time, so on this host the gain lands as CPU rather than wall (discourse 22.75 s to 22.60 s, peak RSS 5.56 GB to 5.42 GB). Ledger entry in docs/design/metrics-ledger.md, section 5.40.

Gate: dump-graph byte-identical against the baseline kernel on all 14 corpora; kernel unit tests 28/28, clippy -D warnings, ast-grep rules; full suite 303 files, 5,178 tests.