Skip to content

perf(vite): speed up inspect invalidation - #620

Merged
webfansplz merged 1 commit into
mainfrom
perf/inspect-indexed-invalidation
Oct 22, 2026
Merged

webfansplz merged 1 commit into
mainfrom
perf/inspect-indexed-invalidation

Conversation

@webfansplz

Copy link
Copy Markdown
Member

Summary

When Vite invalidates a module (for example after a file edit), the inspect store clears that module's records and every record linked to it. To find those links, invalidateNow rescanned all transforms and resolveId records in the scope, and repeated the scan until no new ids were found. Each invalidation therefore cost time proportional to the whole project, and it ran on the main thread right when the user is waiting for the edit to show up.

This PR indexes the records so invalidation only visits the records linked to the invalidated module. The set of cleared records is unchanged.

Changes

  • Add three indexes to each scope: public id → transform ids, id → resolveId records, and public id → resolveId records.
  • invalidateNow walks the links through these indexes (breadth-first) instead of rescanning the scope until it stops changing.
  • Every write to transforms and resolveIds goes through setTransforms, deleteTransforms, addResolveId, and deleteResolveIds, so the indexes stay in sync.
  • Remove the now-unused addInvalidId and matchesInvalid helpers.

Impact

Measured locally with a synthetic project (5,000 modules × 200 lines, half under node_modules, 20 plugins). After all records are written, 200 modules are invalidated and requested again, like an edit once the dev server has settled. Median of 15 runs:

Request time
Without inspect 52 ms
With inspect, before 125 ms (+134%)
With inspect, after 69 ms (+31%)

Cold-start transform time and the background flush are unchanged. A single small edit invalidates only a few modules, so the gain there is a few milliseconds. It matters most in large projects, after editing a module many others depend on, and after dependency re-optimization.

The indexes use some extra memory: each resolveId record is referenced from four index entries.

Copilot AI balanced review requested due to automatic review settings October 22, 2026 04:54

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@620

@vitejs/devtools-kit

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

@vitejs/devtools-oxc

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

@vitejs/devtools-rolldown

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

@vitejs/devtools-vite

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

@vitejs/devtools-vitest

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

commit: 0a8896e

@webfansplz
webfansplz merged commit d29908c into main Oct 22, 2026
10 checks passed
@webfansplz
webfansplz deleted the perf/inspect-indexed-invalidation branch October 22, 2026 06:18
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