Skip to content

Commit fb24e64

Browse files
authored
Merge pull request #1416 from yamadashy/perf/reduce-metrics-batch-size
perf(metrics): Reduce token counting batch size for better worker utilization
2 parents c204571 + f7965b3 commit fb24e64

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

src/core/metrics/calculateSelectiveFileMetrics.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ import type { FileMetrics } from './workers/types.js';
99
// Batch size for grouping files into worker tasks to reduce IPC overhead.
1010
// Each batch is sent as a single message to a worker thread, avoiding
1111
// per-file round-trip costs (~0.5ms each) that dominate when processing many files.
12-
// For 991 files: 991 round-trips → 20 batches, saving ~485ms of IPC overhead.
13-
const METRICS_BATCH_SIZE = 50;
12+
// A size of 10 keeps individual worker tasks small so that workers become available sooner,
13+
// enabling overlap between file metrics and output generation.
14+
// When tokenCountTree is disabled, metrics only processes a small number of top files
15+
// (e.g., topFilesLength * 10 = 50 by default), so a smaller batch size avoids
16+
// a single batch monopolizing one worker.
17+
const METRICS_BATCH_SIZE = 10;
1418

1519
export const calculateSelectiveFileMetrics = async (
1620
processedFiles: ProcessedFile[],

src/core/metrics/workers/calculateMetricsWorker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { freeTokenCounters, getTokenCounter } from '../tokenCounterFactory.js';
77
*
88
* Supports both single-content and batch modes. Batch mode reduces IPC overhead
99
* by processing multiple files per worker round-trip (~0.5ms overhead per round-trip).
10-
* For 991 files, batching with size 50 reduces round-trips from 991 to 20.
10+
* For 991 files, batching with size 10 reduces round-trips from 991 to ~100.
1111
*/
1212

1313
// Initialize logger configuration from workerData at module load time

src/core/security/securityCheck.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ export interface SuspiciousFileResult {
2121
// Batch size for grouping files into worker tasks to reduce IPC overhead.
2222
// Each batch is sent as a single message to a worker thread, avoiding
2323
// per-file round-trip costs that dominate when processing many files.
24-
// A moderate batch size (50) reduces IPC round-trips by ~98% (990 → 20 for a typical repo)
25-
// while keeping enough batches to utilize all available CPU cores.
24+
// Security check always processes all files (~1000 in a typical repo), so a batch size of 50
25+
// already produces ~20 batches — enough to distribute well across available CPU cores.
26+
// (Unlike metrics, which may process only a small number of top files when tokenCountTree
27+
// is disabled, and needs a smaller batch size to avoid one batch monopolizing a worker.)
2628
const BATCH_SIZE = 50;
2729

2830
export const runSecurityCheck = async (

0 commit comments

Comments
 (0)