Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/core/metrics/calculateSelectiveFileMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[],
Expand Down
2 changes: 1 addition & 1 deletion src/core/metrics/workers/calculateMetricsWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/core/security/securityCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Loading