Skip to content

perf(rolldown): speed up session logs - #628

Merged
webfansplz merged 2 commits into
mainfrom
perf/rolldown-log-access
Nov 4, 2026
Merged

webfansplz merged 2 commits into
mainfrom
perf/rolldown-log-access

Conversation

@webfansplz

@webfansplz webfansplz commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Summary

Opening a Rolldown session in DevTools reads the build's logs.json, which gets very large for big projects. On a lobehub SPA build (~29k modules, 6.9M events, 4 GB log), reopening an already-parsed session still took almost a second and blocked the DevTools server in one ~700 ms chunk. This PR makes reopening near-instant and keeps the server responsive while large logs are read.

Changes

  • Summary restore skips the reader index. Restoring a session summary used to parse every sidecar cache, including the reader index (148 MB). It now reads only session-summary.json and the module metrics the module list and chunk sizes rely on (41 MB); the index is loaded on the first full read (module or plugin details).
  • No duplicate cache write. A summary write already writes every sidecar, so the following full read no longer writes the same files again.
  • Binary reader index. reader-index.json is replaced by reader-index.bin (new reader-index-codec.ts). Encoding and decoding yield to the event loop regularly, offsets are stored as f64 so logs over 4 GB work, and a header with the log size and mtime rejects stale or truncated files. The cache version is bumped to 3, so existing caches are rebuilt.
  • Time-sliced parsing. Reading logs.json yields to the event loop about every 8 ms instead of once per 1 MB chunk.

Impact

Measured locally on the lobehub log above (the build's log writer timed out on the last line, so the session is truncated by one event):

Before After
Reopen session (summary, cache present) 0.83 s, longest stall 710 ms, heap 369 MB 0.11 s, longest stall 15 ms, heap 66 MB
First full read after reopening (details) included above 0.35 s, longest stall 58 ms
Cold open (no cache) 14.7 s, longest stall 579 ms ~15.5 s, longest stall 175 ms
Full read right after a cold open 1.1 s, longest stall 494 ms 0 s
Reader index cache 148 MB 77 MB

Cold open is ~5% slower in total because parsing now yields, in exchange for the server staying responsive. Its time is dominated by per-line JSON.parse, GC, and building metrics; skipping large content strings and buffer-based action detection were tried and were slower, so they aren't included.

Copilot AI balanced review requested due to automatic review settings November 4, 2026 06:12
@pkg-pr-new

pkg-pr-new Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@vitejs/devtools

npm i https://pkg.pr.new/@vitejs/devtools@628

@vitejs/devtools-kit

npm i https://pkg.pr.new/@vitejs/devtools-kit@628

@vitejs/devtools-oxc

npm i https://pkg.pr.new/@vitejs/devtools-oxc@628

@vitejs/devtools-rolldown

npm i https://pkg.pr.new/@vitejs/devtools-rolldown@628

@vitejs/devtools-vite

npm i https://pkg.pr.new/@vitejs/devtools-vite@628

@vitejs/devtools-vitest

npm i https://pkg.pr.new/@vitejs/devtools-vitest@628

commit: 1d3a5ad

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Restoring cached sessions without module metrics hides metrics and plugin badges and produces zero module-based sizes, while later full reads do not refresh the affected client data.

1 open issue
What changed in this PR

This PR reduces Rolldown session reopening time and improves DevTools server responsiveness when processing large build logs.

Changes:

  • Defers reader-index and module-metrics loading until a full read and avoids duplicate cache writes.
  • Adds a binary reader-index cache with log validation and support for offsets beyond 4 GB.
  • Adds time-sliced parsing and tests for codec integrity and summary-to-full restoration.
File Description
packages/​rolldown/​src/​node/​rolldown/​reader-index-codec.ts Adds binary index encoding and decoding with periodic yields.
packages/​rolldown/​src/​node/​rolldown/​log-cache.ts Integrates binary caches and lightweight summary restoration.
packages/​rolldown/​src/​node/​rolldown/​events-reader.ts Updates summary state handling and yields during parsing.
packages/​rolldown/​src/​node/​rolldown/​__tests__/​reader-index-cache.test.ts Tests codec round trips, invalid data rejection, and cache restoration.

Review effort: Balanced

@webfansplz
webfansplz marked this pull request as draft November 4, 2026 06:27
Restoring a cached session summary skipped module-metrics-summary.json, so
every module's build_metrics was undefined after reopening. The module list
lost its metrics and plugin badges, and chunk sizes computed from transforms
were zero; a later full read did not refresh the client's module list.
@webfansplz
webfansplz marked this pull request as ready for review November 4, 2026 08:13
@webfansplz
webfansplz merged commit 33795af into main Nov 4, 2026
10 checks passed
@webfansplz
webfansplz deleted the perf/rolldown-log-access branch November 4, 2026 08:15
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.

2 participants