Skip to content

perf(worker): lazy-load coverage provider to reduce worker startup overhead#1110

Merged
9aoy merged 1 commit intomainfrom
perf/lazy-load-coverage-provider
Mar 26, 2026
Merged

perf(worker): lazy-load coverage provider to reduce worker startup overhead#1110
9aoy merged 1 commit intomainfrom
perf/lazy-load-coverage-provider

Conversation

@fi3ework
Copy link
Copy Markdown
Member

Summary

Background

Every worker process statically imports the coverage module chain (7704.js4411.js), loading ~108KB of picomatch/glob code at startup — even when coverage is disabled (the common case).

Implementation

  • Changed createCoverageProvider from a top-level static import to a dynamic import() guarded by coverage.enabled.
  • This removes 7704.js (1.6KB) and its transitive dependency 4411.js (106KB) from every worker's static import chain. These chunks are now only loaded once in the main process when coverage is actually enabled.

Worker static JS asset reduction:

+------------------+----------+----------+---------+
| Chunk            | baseline | cov-lazy | Δ       |
+------------------+----------+----------+---------+
| worker.js chain  | 262KB    | 163KB    | -99KB   |
| 7704.js (cov)    | 52 PIDs  | 1 PID    | -98%    |
| 4411.js (glob)   | 54 PIDs  | 1 PID    | -98%    |
+------------------+----------+----------+---------+

Benchmark

Fixture: 50 test files × 20 tests (1000 tests), 14-core machine, isolateWorkers: true, NODE_COMPILE_CACHE disabled.

hyperfine --warmup 5 --runs 30

Benchmark 1: baseline
  Time (mean ± σ):     571.0 ms ±  15.9 ms    [User: 3478.4 ms, System: 709.6 ms]
  Range (min … max):   546.9 ms … 616.1 ms    30 runs

Benchmark 2: cov-lazy
  Time (mean ± σ):     558.9 ms ±  25.5 ms    [User: 3264.9 ms, System: 716.2 ms]
  Range (min … max):   533.6 ms … 637.5 ms    30 runs

Summary
  cov-lazy ran
    1.02 ± 0.05 times faster than baseline

Wall clock: ~2% (limited by 14-core parallelism). User CPU: -214ms (-6.1%), reflecting ~4ms less parse/compile per worker × 52 worker processes.

User Impact

Marginal wall-clock improvement for typical runs; more visible on lower-core machines or larger test suites.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

…erhead

Defer  import from static to dynamic ,
only loading when  is true. This prevents every worker
process from parsing ~100KB of picomatch/glob code (4411.js + 7704.js)
at startup when coverage is disabled (the common case).

Verified with module tracing: HEAD loads 4411.js in all 52+ worker PIDs,
while this change loads it only once in the main process. Benchmark shows
~4.4% User CPU reduction across worker processes.

Amp-Thread-ID: https://ampcode.com/threads/T-019d2927-404e-7449-b0c7-5798bdd49e6f
Co-authored-by: Amp <amp@ampcode.com>
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@github-actions
Copy link
Copy Markdown

Rsdoctor Bundle Diff Analysis

⚠️ Note: The latest commit (f1326cf2af) does not have baseline artifacts. Using commit f0de5f85f0 for baseline comparison instead. If this seems incorrect, please wait a few minutes and try rerunning the workflow.

Found 12 projects in monorepo, 1 project with changes.

📊 Quick Summary
Project Total Size Change
adapter-rsbuild 2.1 KB 0
adapter-rslib 23.1 KB 0
adapter-rspack 5.9 KB 0
browser 2.0 MB 0
browser-react 3.7 KB 0
browser-ui 804.3 KB 0
coverage-istanbul 9.1 KB 0
core/browser 971.6 KB 0
core/loaders 869.0 B 0
core/main 1.5 MB +124.0 B (0.0%)
vscode/extension 60.2 MB 0
vscode/worker 14.4 KB 0
📋 Detailed Reports (Click to expand)

📁 core/main

Path: packages/core/.rsdoctor/main/rsdoctor-data.json

📌 Baseline Commit: f0de5f85f0 | PR: #1107

Metric Current Baseline Change
📊 Total Size 1.5 MB 1.5 MB +124.0 B (0.0%)
📄 JavaScript 1.5 MB 1.5 MB +124.0 B (0.0%)
🎨 CSS 0 B 0 B 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 75.4 KB 75.4 KB 0

📦 Download Diff Report: core/main Bundle Diff

Generated by Rsdoctor GitHub Action

@9aoy 9aoy merged commit 722f687 into main Mar 26, 2026
18 checks passed
@9aoy 9aoy deleted the perf/lazy-load-coverage-provider branch March 26, 2026 09:04
@9aoy 9aoy mentioned this pull request Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants