Skip to content

perf(vite): skip storing unchanged transform results - #618

Open
webfansplz wants to merge 1 commit into
mainfrom
perf/inspect-dedupe-unchanged
Open

webfansplz wants to merge 1 commit into
mainfrom
perf/inspect-dedupe-unchanged

Conversation

@webfansplz

Copy link
Copy Markdown
Member

Summary

When a plugin's transform returns code identical to its input (e.g. return code or return { code }), the inspect store wrote a second full copy of that code to the payload archive. This PR reuses the existing payload instead.

Changes

  • In writeDataBatch, track the latest code queued for each module in the batch. If a step's result equals that code, point the step at the same payload index instead of pushing a new value.
  • Reset the tracking whenever a new source or load result starts a module's snapshot, so steps never share a payload across transform requests.
  • Sharing is safe for reclaim: ranges are released per module, and collectPayloadRanges already dedupes them.

Results from a hook that returns undefined were already skipped, so this only affects the identical-string case. Dedupe is scoped to a single write batch on purpose. Holding each module's latest code across batches would keep it in memory, which the store is designed to avoid.

Impact

Measured locally with a synthetic project (5,000 modules × 200 lines, 20 plugins, 5 of which return their input unchanged), median of 10 runs:

Before After
Payload archive 688 MB 459 MB (−33%)
Flush after transforms 626 ms 461 ms (−26%)
Transform time 862 ms 870 ms (within noise)

The savings scale with how many plugins return their input unchanged.

Copilot AI balanced review requested due to automatic review settings October 21, 2026 06:51

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@pkg-pr-new

pkg-pr-new Bot commented Oct 21, 2026

Copy link
Copy Markdown

Open in StackBlitz

@vitejs/devtools

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

@vitejs/devtools-kit

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

@vitejs/devtools-oxc

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

@vitejs/devtools-rolldown

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

@vitejs/devtools-vite

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

@vitejs/devtools-vitest

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

commit: 1091539

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