Skip to content

perf(rolldown): keep loaded sessions cached and cap reader memory - #634

Merged
webfansplz merged 2 commits into
mainfrom
perf/rolldown-reader-cache
Nov 12, 2026
Merged

webfansplz merged 2 commits into
mainfrom
perf/rolldown-reader-cache

Conversation

@webfansplz

Copy link
Copy Markdown
Member

Background

The Rolldown UI keeps parsed session logs in an in-memory reader cache (RolldownEventsReader), capped at 32 readers by count only.

Two problems came out of that:

  • Listing sessions evicted the sessions being viewed. list() created a reader for every session's meta.json. With more than 32 sessions, opening the session list pushed the loaded logs.json readers (e.g. both sides of a compare view) out of the cache, so the next interaction re-read and re-parsed the full log, which can be hundreds of MB.
  • No memory bound. The cap counted readers, not data, so a few large fully-read sessions could hold several GiB.

Changes

  • logs-manager.ts: session metas are parsed by a new readSessionMeta() and cached by file size + mtime, outside the reader cache. list() and the loadSession* helpers use it; deleteSession drops the cached entry. Event ids match what the events reader assigns.
  • events-reader.ts: the reader cache is also bounded by total log bytes of fully read sessions (1 GiB). The two most recently used readers and readers with a pending read are never evicted. Pruning also runs after reads complete.
  • Added reader-cache.test.ts covering both behaviors.

Copilot AI balanced review requested due to automatic review settings November 10, 2026 03:10
@pkg-pr-new

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

Copy link
Copy Markdown

Open in StackBlitz

@vitejs/devtools

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

@vitejs/devtools-kit

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

@vitejs/devtools-oxc

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

@vitejs/devtools-rolldown

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

@vitejs/devtools-vite

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

@vitejs/devtools-vitest

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

commit: 935ad87

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

Concurrent-load cache pruning can dispose of a reader before its awaiting caller resumes, causing successful loads to return empty data.

1 open issue
What changed in this PR

This PR separates session metadata caching from Rolldown’s log-reader cache, reducing repeated log parsing when listing sessions and limiting cached log data.

Changes:

  • Cache session metadata by file size and modification time without creating log readers.
  • Add a 1 GiB log-byte budget, preserving the two most recent readers and pending reads.
  • Add regression tests for session-list cache retention and budget-based eviction.
File Description
packages/​rolldown/​src/​node/​rolldown/​logs-manager.ts Adds metadata caching and uses it across listing and session loading.
packages/​rolldown/​src/​node/​rolldown/​events-reader.ts Adds byte-budget pruning, including pruning after reads complete.
packages/​rolldown/​src/​node/​rolldown/​__tests__/​reader-cache.test.ts Tests cache retention and eviction protections.

Review effort: Balanced

@webfansplz
webfansplz merged commit d844598 into main Nov 12, 2026
10 checks passed
@webfansplz
webfansplz deleted the perf/rolldown-reader-cache branch November 12, 2026 15:34
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