Skip to content

perf(batch): avoid retaining clean fix results - #188

Merged
luojiyin1987 merged 2 commits into
masterfrom
perf/compact-clean-fix-results
Sep 13, 2026
Merged

luojiyin1987 merged 2 commits into
masterfrom
perf/compact-clean-fix-results

Conversation

@luojiyin1987

Copy link
Copy Markdown
Contributor

Problem

In fix mode, batchLint() accumulates full BatchLintItem results including fixedResult.result (the complete fixed Markdown text) for ALL files, even clean ones. The allResults array is only consumed by getFixDevMetrics() which only needs path, fixedResult.metrics, and fixedResult.convergence.

This causes unbounded memory growth proportional to total input size:

worker working set: bounded (concurrency threads)
result retention:   unbounded (grows with file count × file size)

Example: 10k clean files × 1 MiB each → ~10 GiB retained in allResults.

Solution

Project clean fix items in the worker to a compact form before returning across the thread boundary. The full Markdown text is never structured-cloned back to the main thread for files that don't need writing.

Changes

  • src/types.ts — Add CompactFixedResult interface and isFullFixedResult type guard
  • src/utils/lint-worker.ts — Project clean items to compact form (only metrics/convergence)
  • src/cli/run-lint.ts — Use type guard in write path

Closes #187

- Add CompactFixedResult type (Pick<FixedResult, 'metrics' | 'convergence'>)
- Project clean fix items in worker before cross-thread return
- Add isFullFixedResult type guard for narrowing
- Add benchmark script for RSS comparison

Benchmark results (1000 files × 64 KiB, --fix --threads 4):
  baseline: 1500.9 MiB avg peak RSS
  compact:  1436.0 MiB avg peak RSS
  delta:    -64.9 MiB (4.3%)

Benchmark results (5000 files × 64 KiB, --fix --threads 4):
  baseline: 1852.7 MiB avg peak RSS
  compact:  1515.5 MiB avg peak RSS
  delta:    -337.2 MiB (18.2%)
@luojiyin1987
luojiyin1987 merged commit 1478ce0 into master Sep 13, 2026
6 checks passed
@luojiyin1987
luojiyin1987 deleted the perf/compact-clean-fix-results branch September 13, 2026 03:15
luojiyin1987 added a commit that referenced this pull request Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(batch): avoid retaining clean fix results in allResults

1 participant