perf(metrics): Batch token counting IPC to reduce worker round-trip overhead#1411
perf(metrics): Batch token counting IPC to reduce worker round-trip overhead#1411
Conversation
⚡ Performance Benchmark
Details
History411ce28 refactor(metrics): Use batchResults.flat() instead of manual loop
1c6b5a8 perf(metrics): Batch token counting IPC to reduce worker round-trip overhead
|
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThis PR introduces a new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1411 +/- ##
==========================================
- Coverage 87.42% 87.26% -0.17%
==========================================
Files 116 117 +1
Lines 4397 4420 +23
Branches 1020 1021 +1
==========================================
+ Hits 3844 3857 +13
- Misses 553 563 +10 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Deploying repomix with
|
| Latest commit: |
7f401d9
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://a66133f0.repomix.pages.dev |
| Branch Preview URL: | https://perf-batch-metrics-token-cou.repomix.pages.dev |
…verhead Selective file metrics previously sent one IPC round-trip per file to worker threads for token counting. With ~991 files and ~0.5ms overhead per round-trip, this added ~495ms of pure IPC waste. This change introduces batch mode for the metrics worker, grouping files into batches of 50 before sending to workers. This reduces round-trips from 991 to 20. Type safety improvement over the original approach: instead of scattering `as number` casts across all callers, a new metricsWorkerRunner module centralizes the type narrowing in two helper functions (runTokenCount and runBatchTokenCount), keeping all other modules fully type-safe. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
411ce28 to
7f401d9
Compare
Batch token counting items into groups of 50 per worker task instead of sending individual files. This reduces worker thread IPC round-trips from ~991 to ~20 for a typical repository, significantly cutting thread creation and message-passing overhead.
Changes
TokenCountBatchTask/MetricsWorkerTask/MetricsWorkerResulttypes andcountTokensBatchhandler tocalculateMetricsWorkermetricsWorkerRunner.tswithMetricsTaskRunnertype alias and type-saferunTokenCount/runBatchTokenCounthelpers — centralizesascasts in one place instead of scattering them across callerscalculateSelectiveFileMetricswithMETRICS_BATCH_SIZE=50batchingcalculateOutputMetrics,calculateGitDiffMetrics,calculateGitLogMetricsto userunTokenCounthelperunifiedWorkertask inference to recognize batch metrics tasks (items+encoding)Benchmark (from prior testing, repomix on itself, ~991 files)
Checklist
npm run testnpm run lint