Commit a890579
committed
perf(output): Defer line-count and markdown-delimiter scans with lazy render-context getters
createRenderContext eagerly ran calculateFileLineCounts and
calculateMarkdownDelimiter — two full scans over every packed file's
content (~5.5MB) — on every run, even though fileLineCounts is only
consumed by skill generation and markdownCodeBlockDelimiter only by the
markdown/skill templates. Memoized getters defer both scans, so the
default XML (and plain/JSON) path never pays for them. Output is
byte-identical (verified with cmp for xml and markdown styles); when a
template or packSkill touches the property, the same computation runs
once and is cached.
Why this clears the bar now when earlier rounds rejected it: this
round's tail profiling showed that on warm runs (token cache hit) the
metrics workers resolve instantly and git token tasks complete ~28ms
before produceOutput, so generateOutput is the sole main-thread
bottleneck at the tail — the scans are wall-visible, not hidden behind
the parallel metrics branch as previously assumed.
Benchmark (packing this repo, warm, quiet 4-core Linux, interleaved
ABBA pairs, node bin/repomix.cjs --quiet):
- batch 1 (20 pairs): median delta -21.7ms, mean -20.1ms, t=-3.51, 15/20 improved
- batch 2 (30 pairs): median delta -25.6ms, mean -18.0ms, t=-2.49, 19/30 improved
- batch 3 (40 pairs): median delta -40.3ms, mean -40.9ms, t=-6.71, 37/40 improved
- pooled (90 pairs): mean -28.6ms on a ~1045ms baseline = -2.7%
Isolated scan cost is ~11-16ms (warm); the larger e2e delta is
consistent with reduced allocation/GC pressure from dropping the
per-line match(/\n/g) array allocations at peak heap.
intent(perf-tuning): automated round targeting >=2% end-to-end CLI improvement with behavior preserved
decision(render-context): memoized getters over style-conditional skips — RenderContext shape and all call sites unchanged, and any consumer that does read the properties still gets identical values
rejected(file-search): gitignore:false + prebuilt globby predicate measured -5.2% e2e but unshippable — depends on globby's unexported ignore.js internals (exports-map patch won't exist for npm consumers) and loses globby's gitignore-pattern directory pruning, risking large traversal regressions on repos with big ignored dirs and no negation patterns
learned(metrics-tail): on warm runs the tail critical path is produceOutput -> write -> wrapper extraction; git diff/log token tasks finish ~28ms earlier, so render-side CPU cuts are wall-visible up to that slack
https://claude.ai/code/session_01RD8vNvv1qtYV8BgdxMU7js1 parent 0fe40b4 commit a890579
1 file changed
Lines changed: 13 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
79 | 84 | | |
80 | 85 | | |
81 | 86 | | |
| |||
89 | 94 | | |
90 | 95 | | |
91 | 96 | | |
92 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
93 | 101 | | |
94 | 102 | | |
95 | 103 | | |
96 | 104 | | |
97 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
98 | 109 | | |
99 | 110 | | |
100 | 111 | | |
| |||
0 commit comments