Repository navigation
Description
Summary
After the outlier-driven perf round (residual = actual / rate-model-predicted, via gitgalaxy-raw-output/tools/rank_outliers.py), the single-hot-path outliers are largely fixed — ghostty (ReDoS), merge-node-client (import-graph resolution, #3062). The remaining top residuals are not single bugs; they are all the same structural cost, so chasing them one repo at a time has diminishing returns. This issue proposes attacking the shared cost instead.
Evidence (this round's investigations)
| repo | residual | verdict |
|---|---|---|
| merge-node-client | 14× | fixed — O(candidates×pathlib) import resolution (#3062) |
| nx (TS) | 4.1× | structural — per-file work; graph resolves in 0.5s |
| node-linux-x64 | 3.0× | structural — 2,724 headerless .h, language detection-bound; no safe win (a detection-content cap broke cross-language crucible parity) |
| sokol-zig | 2.0× | structural — vendored large C headers; one latent quadratic removed (#3068) |
In every structural case the dominant CPU cost is detector.py::coding_analysis running each language's full rule set as pattern.finditer(seg_code) over the whole segment (≈40 rules for C, more for TS), plus the per-hit spatial-map/offset bookkeeping. On big files this is the bottleneck; it scales with files × rules × filesize and is legitimate work (no bug), which is why per-repo fixes barely move it.
Proposed work (the actual lever)
Optimize the shared coding_analysis rule pass so the whole corpus benefits:
- Cheap content pre-filter per rule. Many rules can't match a segment lacking a required literal/keyword. A
substring in seg_code(or a fast prefilter set) gate beforefinditerwould skip a large fraction of the ~40 regexes on most files. (Same idea as the'=' in linevar-decl pre-filter, perf(detector): skip =-less lines before the var-decl backtracking regex #3063, generalized.) Must preserve exact match sets — validate against the golden crucible. - Combined/alternation scan. Investigate a single combined pass (one automaton) over the segment instead of N independent
finditercalls, or grouping rules that share anchors. Higher risk to parity; needs careful per-rule attribution. - Right-size the work to the file. Confirm segments/streams aren't scanned more than once and that large files don't re-run identical passes.
Target: reduce the per-file coding_analysis cost that dominates nx/node/sokol-zig and every other large repo, rather than one outlier.
Methodology note (save the next person a day)
A thread-based statistical sampler systematically over-attributes GIL-releasing work — syscalls (iterdir/stat), tiktoken.encode, and re calls all release the GIL, so the sampler thread over-counts the Python frame parked at that call. It falsely fingered tiktoken (~85%/34% vs ~1% real) and a directory census (77% vs 1.2% real) in this round. Use cProfile for CPU-bound Python attribution; treat the sampler as reliable only for pure-Python loops.
References
- Fixes shipped this round: perf(network): memoize Stage-2 candidate stem-stripping in import resolution #3062 (merged), perf(detector): skip =-less lines before the var-decl backtracking regex #3063 (var-decl pre-filter), perf(detector): hoist the is_public api-window check out of an O(F*A) scan #3068 (is_public O(F×A) quadratic).
- Reproduce residual ranking:
python tools/rank_outliers.py v<version>in gitgalaxy-raw-output (writesspeed_charts/outliers.json).
Activity
perf(detector): required-literal prefilter for the shared coding_anal…
tooling(perf): reusable phase A/B harness + perf-ab skill (#3178)