Skip to content

perf(vite): reduce inspect write batch overhead - #622

Merged
webfansplz merged 1 commit into
mainfrom
perf/inspect-batch-module-state
Oct 23, 2026
Merged

webfansplz merged 1 commit into
mainfrom
perf/inspect-batch-module-state

Conversation

@webfansplz

Copy link
Copy Markdown
Member

Summary

After a cold start or a burst of edits, the inspect store writes its queued records in the background on the main thread, where it competes with Vite for CPU. For every record, writeDataBatch built a composite key with `${scope}\0${moduleId}` and looked it up in two separate maps: one to check whether the module's source was already stored, one to dedupe unchanged results. Building and hashing a new string per record added up across hundreds of thousands of records.

This PR keeps one state object per module in the batch, looked up by scope and then module id, so each record does a single lookup without building a key. Behavior is unchanged.

Changes

  • Replace the sourceState and latestCode maps with one ModuleBatchState per module, stored in a Map<scope, Map<moduleId, ModuleBatchState>>.
  • hasSource and pushCode read and update that state object directly.
  • Remove the now-unused scopeKey helper.

Impact

Measured locally with a synthetic project (half of the modules under node_modules, 20 plugins). Main-thread busy time while the store writes everything queued after a cold start, median of 10 runs:

Modules Before After
5,000 403 ms 364 ms (−10%)
15,000 1,596 ms 1,463 ms (−8%)

Memory, transform time, and request latency after edits are unchanged within noise.

Copilot AI balanced review requested due to automatic review settings October 22, 2026 08:13

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 22, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@vitejs/devtools

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

@vitejs/devtools-kit

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

@vitejs/devtools-oxc

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

@vitejs/devtools-rolldown

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

@vitejs/devtools-vite

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

@vitejs/devtools-vitest

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

commit: 52ac7cf

@webfansplz
webfansplz force-pushed the perf/inspect-batch-module-state branch from 62bac94 to 52ac7cf Compare October 23, 2026 03:58
@webfansplz
webfansplz merged commit 22f6cd0 into main Oct 23, 2026
10 checks passed
@webfansplz
webfansplz deleted the perf/inspect-batch-module-state branch October 23, 2026 04:01
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