kernel: JavaScript member calls stop rescanning whole files per ref

Merged
BO
2mo ago
+198-84

First batch of the performance pass. Output is unchanged.

The per-verdict-class profiler put pretix's largest resolution cost in JavaScript: 30,792 call refs ended unresolved at about 200 µs each, in bound_receiver_claim. Pretix ships vendored and minified JS, and four steps each did work proportional to the file or the line on every ref:

  • Await gate. It scanned every line of the file for = await x(. The pattern needs a literal await, so each file now caches its await lines and the gate scans only those.
  • Receiver-type scan. It walked backwards from the call to the scope start, often line 1. Every receiver pattern needs the receiver literal, so the lines containing it are found once per (file, receiver) with memmem, and only those are scanned, highest first as before.
  • Factory initializer. It was re-parsed for every ref through the same binding, and parens_end walked the rest of the line after the closing paren. The parse is now memoized per binding, and parens_end returns at the close.
  • Line-length guard. utf16_len counts from bytes, and the 10,000-unit guard is decided from the byte length when that settles it.
corpus (wall / resolution)beforeafter
pretix10.6 s / 7.7 s9.0 s / 6.0 s
firefly-iii7.9 s / 5.2 s6.7 s / 4.7 s
linux-fs11.7 s / 6.2 s10.5 s / 5.7 s
warp-drive4.6 s / 2.6 s4.3 s / 2.2 s

Peak RSS is within run-to-run noise. The ledger gets §5.43. It also corrects §5.42: tree-sitter's child(i) is linear, not log(i), though the neutral measurement there stands.

Gate: dump-graph byte-identical against the #114 kernel on all 15 corpora. Also: kernel unit tests 35/35 (new: byte-counted utf16_len); clippy -D warnings; ast-grep rules; full suite 303 files, 5,178 tests.