diff --git a/src/core/metrics/calculateSelectiveFileMetrics.ts b/src/core/metrics/calculateSelectiveFileMetrics.ts index 5abd0d0de..773cccc52 100644 --- a/src/core/metrics/calculateSelectiveFileMetrics.ts +++ b/src/core/metrics/calculateSelectiveFileMetrics.ts @@ -9,8 +9,12 @@ import type { FileMetrics } from './workers/types.js'; // Batch size for grouping files into worker tasks to reduce IPC overhead. // Each batch is sent as a single message to a worker thread, avoiding // per-file round-trip costs (~0.5ms each) that dominate when processing many files. -// For 991 files: 991 round-trips → 20 batches, saving ~485ms of IPC overhead. -const METRICS_BATCH_SIZE = 50; +// A size of 10 keeps individual worker tasks small so that workers become available sooner, +// enabling overlap between file metrics and output generation. +// When tokenCountTree is disabled, metrics only processes a small number of top files +// (e.g., topFilesLength * 10 = 50 by default), so a smaller batch size avoids +// a single batch monopolizing one worker. +const METRICS_BATCH_SIZE = 10; export const calculateSelectiveFileMetrics = async ( processedFiles: ProcessedFile[], diff --git a/src/core/metrics/workers/calculateMetricsWorker.ts b/src/core/metrics/workers/calculateMetricsWorker.ts index 65b56fba9..a09fa1fba 100644 --- a/src/core/metrics/workers/calculateMetricsWorker.ts +++ b/src/core/metrics/workers/calculateMetricsWorker.ts @@ -7,7 +7,7 @@ import { freeTokenCounters, getTokenCounter } from '../tokenCounterFactory.js'; * * Supports both single-content and batch modes. Batch mode reduces IPC overhead * by processing multiple files per worker round-trip (~0.5ms overhead per round-trip). - * For 991 files, batching with size 50 reduces round-trips from 991 to 20. + * For 991 files, batching with size 10 reduces round-trips from 991 to ~100. */ // Initialize logger configuration from workerData at module load time diff --git a/src/core/security/securityCheck.ts b/src/core/security/securityCheck.ts index 30e5b386e..d0d64576d 100644 --- a/src/core/security/securityCheck.ts +++ b/src/core/security/securityCheck.ts @@ -21,8 +21,10 @@ export interface SuspiciousFileResult { // Batch size for grouping files into worker tasks to reduce IPC overhead. // Each batch is sent as a single message to a worker thread, avoiding // per-file round-trip costs that dominate when processing many files. -// A moderate batch size (50) reduces IPC round-trips by ~98% (990 → 20 for a typical repo) -// while keeping enough batches to utilize all available CPU cores. +// Security check always processes all files (~1000 in a typical repo), so a batch size of 50 +// already produces ~20 batches — enough to distribute well across available CPU cores. +// (Unlike metrics, which may process only a small number of top files when tokenCountTree +// is disabled, and needs a smaller batch size to avoid one batch monopolizing a worker.) const BATCH_SIZE = 50; export const runSecurityCheck = async (