Summary
Speed up scanning on large monorepos via worker-thread parallel detector execution and a shareable (content-addressed) cache key, building on the existing scan cache.
type: rfc — settle the parallelism model and cache key/versioning contract before implementation.
Motivation
DebtLens runs detectors in-process; on large repos this is single-threaded and re-parses unchanged files each run unless the local cache hits. Two improvements compound: (1) parallelize across files/detectors using worker threads, and (2) make the scan cache shareable across machines/CI so a warm cache from one runner benefits others.
Proposed behavior
- Parallel execution: shard files across a pool of
worker_threads, run detectors per shard, then merge ScanResults deterministically (stable ordering regardless of worker scheduling). --concurrency <n> with a sensible default (CPU-based); --concurrency 1 preserves today's behavior.
- Shareable cache: extend the current cache (
src/core/scanCache.ts) with a content-addressed key (file hash + rule config hash + DebtLens version) and an optional --cache-dir so CI can restore/save it as an artifact. Atomic writes are already used; keep them.
- Determinism and parallelism-safety are first-class requirements (cross-file rules like
duplicate-logic, import-cycle, duplicated-literal need a merge/aggregation phase, not naive per-file sharding).
Implementation surface
- New
src/core/parallelScan.ts orchestrating worker_threads; refactor src/core/scan.ts to separate per-file detection from cross-file aggregation so the latter runs after merge.
- Extend
src/core/scanCache.ts with the content-addressed key and --cache-dir.
- CLI flags in
src/cli/commands/scan.ts / src/cli/scanPipeline.ts.
- Benchmarks: extend
scripts/benchmark.mjs to compare serial vs parallel; assert identical findings.
- Tests: determinism (parallel result == serial result), cache hit/miss, key invalidation on config/version change.
Acceptance criteria
Difficulty: large.
Summary
Speed up scanning on large monorepos via worker-thread parallel detector execution and a shareable (content-addressed) cache key, building on the existing scan cache.
Motivation
DebtLens runs detectors in-process; on large repos this is single-threaded and re-parses unchanged files each run unless the local cache hits. Two improvements compound: (1) parallelize across files/detectors using worker threads, and (2) make the scan cache shareable across machines/CI so a warm cache from one runner benefits others.
Proposed behavior
worker_threads, run detectors per shard, then mergeScanResults deterministically (stable ordering regardless of worker scheduling).--concurrency <n>with a sensible default (CPU-based);--concurrency 1preserves today's behavior.src/core/scanCache.ts) with a content-addressed key (file hash + rule config hash + DebtLens version) and an optional--cache-dirso CI can restore/save it as an artifact. Atomic writes are already used; keep them.duplicate-logic,import-cycle,duplicated-literalneed a merge/aggregation phase, not naive per-file sharding).Implementation surface
src/core/parallelScan.tsorchestratingworker_threads; refactorsrc/core/scan.tsto separate per-file detection from cross-file aggregation so the latter runs after merge.src/core/scanCache.tswith the content-addressed key and--cache-dir.src/cli/commands/scan.ts/src/cli/scanPipeline.ts.scripts/benchmark.mjsto compare serial vs parallel; assert identical findings.Acceptance criteria
--concurrencyand--cache-dirwork;--concurrency 1matches current behavior.npm run test:allpasses.Difficulty: large.