/** * SMI-1308: Worker Thread Pool for Parallel File Parsing * SMI-1337: Added metrics integration * * Uses Node.js worker_threads for true parallelism, * bypassing the single-threaded event loop limitation. * * @see docs/internal/architecture/multi-language-analysis.md * @module analysis/worker-pool */ import { isMainThread, parentPort, workerData } from 'worker_threads'; import { EventEmitter } from 'events'; import type { ParseTask, WorkerResult, WorkerPoolOptions } from './worker-types.js'; export type { ParseTask, WorkerResult, WorkerPoolOptions } from './worker-types.js'; /** * Worker thread pool for parallel file parsing * * Uses Node.js worker_threads for true parallelism, * bypassing the single-threaded event loop limitation. * * For small batches (< minBatchForWorkers), parses inline * to avoid worker overhead. * * @example * ```typescript * const pool = new ParserWorkerPool({ poolSize: 4 }) * * const tasks = files.map(f => ({ * filePath: f.path, * content: f.content, * language: 'typescript' * })) * * const results = await pool.parseFiles(tasks) * console.log(`Parsed ${results.length} files`) * * pool.dispose() * ``` */ export declare class ParserWorkerPool extends EventEmitter { private workers; private taskQueue; private activeWorkers; private readonly poolSize; private readonly minBatchForWorkers; private readonly metrics; private disposed; private router; private routerPromise; constructor(options?: WorkerPoolOptions); /** * SMI-1330/1331: Get or create shared router instance * Lazily initializes the router on first use and caches it */ private getRouter; /** * SMI-1330/1331: Initialize router with all adapters */ private initializeRouter; /** * Parse files in parallel using worker threads * * SMI-1337: Records worker pool metrics. * * @param tasks - Array of parse tasks * @returns Array of worker results * @throws Error if pool has been disposed */ parseFiles(tasks: ParseTask[]): Promise; /** * Record parse metrics for completed results * SMI-1337: Helper to record metrics after parsing */ private recordParseMetrics; /** * Parse files inline (no workers) * * Used for small batches where worker overhead exceeds benefit. * SMI-1330/1331: Uses cached router to avoid recreation overhead */ private parseInline; /** * Parse files using worker threads * * Chunks tasks across available workers for parallel processing. */ private parseWithWorkers; /** * Dispatch a chunk of tasks to a worker */ private dispatchToWorker; /** * Get pool statistics * * SMI-1337: Also updates metrics. * * @returns Current pool statistics */ getStats(): { poolSize: number; activeWorkers: number; queuedTasks: number; utilization: number; }; /** * Dispose of worker pool * * Terminates all workers and clears the task queue. * SMI-1330/1331: Also disposes cached router */ dispose(): void; } export { isMainThread, parentPort, workerData }; //# sourceMappingURL=worker-pool.d.ts.map