You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
perf(core): Eliminate redundant output tokenization by deriving total from file tokens
Replace the expensive full-output tokenization pass (~350ms for 3.8MB) with a
computation derived from individual file token counts plus an estimated template
overhead. Since the output is primarily composed of the same file contents that
are already tokenized individually, the total output token count can be accurately
computed as: sum(file_tokens) + overhead_chars × char_to_token_ratio.
Key changes:
- calculateMetrics: Always tokenize all files individually (not just top 50),
then compute total output tokens from the sum of file tokens plus estimated
template overhead. This eliminates the separate full-output tokenization pass
that previously dominated metrics time.
- outputGenerate/createRenderContext: Skip calculateFileLineCounts and
calculateMarkdownDelimiter for non-markdown output styles (xml, json, plain).
These functions scan all file contents but are only consumed by the markdown
template and the skill generation path (which sets style to 'markdown').
- fileSearch/searchFiles: Run file search and empty-directory search globby
calls in parallel instead of sequentially when includeEmptyDirectories is
enabled.
Benchmark results (repomix on its own repo, 998 files, 15 runs each):
Before: 1572ms mean
After: 1353ms mean
Improvement: 219ms (13.9%)
The output token count approximation has <0.04% variance from the previous
chunk-based approach, which itself introduced similar boundary effects by
splitting at arbitrary 200KB positions.
https://claude.ai/code/session_01H56SP71cxhxE6CyQzUH6cc
0 commit comments