Skip to content

perf(core): split monolithic worker bundle into lazy-loaded chunks#1085

Merged
fi3ework merged 1 commit intomainfrom
perf/chunk-splitting
Mar 24, 2026
Merged

perf(core): split monolithic worker bundle into lazy-loaded chunks#1085
fi3ework merged 1 commit intomainfrom
perf/chunk-splitting

Conversation

@fi3ework
Copy link
Copy Markdown
Member

@fi3ework fi3ework commented Mar 23, 2026

Benchmark

tested in Rstest self codebase.

unit test

hyperfine --warmup 8 --runs 30 \
  --command-name 'perf' "cd '/Users/bytedance/Projects/worktrees/tree/dev1' && pnpm test" \
  --command-name 'baseline' "cd '/Users/bytedance/Projects/rstest' && pnpm test"
Benchmark 1: perf
  Time (mean ± σ):      1.175 s ±  0.017 s    [User: 5.662 s, System: 1.356 s]
  Range (min … max):    1.144 s …  1.210 s    30 runs
 
Benchmark 2: baseline
  Time (mean ± σ):      1.235 s ±  0.052 s    [User: 6.133 s, System: 1.375 s]
  Range (min … max):    1.192 s …  1.451 s    30 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Summary
  perf ran
    1.05 ± 0.05 times faster than baseline

sliced E2E test (exclude noisy cases like browser mode)

hyperfine --warmup 3 --runs 10 \
  --command-name 'dev1-e2e-slice' "cd '/Users/bytedance/Projects/worktrees/tree/dev1/e2e' && pnpm test test-api lifecycle projects" \
  --command-name 'rstest-e2e-slice' "cd '/Users/bytedance/Projects/rstest/e2e' && pnpm test test-api lifecycle projects"
Benchmark 1: dev1-e2e-slice
  Time (mean ± σ):      8.484 s ±  1.379 s    [User: 39.350 s, System: 13.961 s]
  Range (min … max):    7.376 s … 12.163 s    10 runs
 
Benchmark 2: rstest-e2e-slice
  Time (mean ± σ):      9.081 s ±  0.384 s    [User: 45.145 s, System: 14.580 s]
  Range (min … max):    8.854 s … 10.146 s    10 runs
 
Summary
  dev1-e2e-slice ran
    1.07 ± 0.18 times faster than rstest-e2e-slice

Summary

Background

The Worker process loaded a single monolithic 742KB chunk (1949.js) at startup, containing all runtime dependencies including snapshot utilities and fake timers — even when they weren't needed for every test run. This added unnecessary parse/compile overhead to Worker initialization.

Implementation

  • Convert SnapshotPlugin from a static import to a dynamic import() in createRstestRuntime(), parallelized with createRunner() via Promise.all
  • Convert FakeTimers from a static import to a dynamic import() in createRstestUtilities()
  • Make snapshotPlugin an optional parameter on createExpect() (passed from createRstestRuntime after dynamic load)
  • Add a vendor-assertion splitChunks cache group to extract chai/@vitest/expect/spy/utils into a stable-named chunk for better V8 compile cache reuse

User Impact

Reduced Worker startup overhead by deferring ~165KB of code (snapshot + fake-timers) to first use. The stable vendor-assertion.js chunk name improves V8 compile cache hit rate across rebuilds.

Checklist

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

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9bcebe9502

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Convert snapshot and fakeTimers from static imports to dynamic imports,
and extract assertion vendor deps into a stable named chunk. This reduces
Worker startup cost by deferring code that is only needed on first use
(snapshot matching, fake timers) and improves V8 compile cache hit rate
via stable chunk filenames.
@fi3ework fi3ework merged commit 31ed6c6 into main Mar 24, 2026
28 of 30 checks passed
@fi3ework fi3ework deleted the perf/chunk-splitting branch March 24, 2026 03:43
@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