Skip to content

perf(vite): speed up inspect module list - #623

Open
webfansplz wants to merge 1 commit into
mainfrom
perf/inspect-module-list
Open

webfansplz wants to merge 1 commit into
mainfrom
perf/inspect-module-list

Conversation

@webfansplz

Copy link
Copy Markdown
Member

Summary

Two costs that grow with project size made the inspect collector compete with Vite for the main thread:

  1. The public module id cache stopped working in large projects. It was capped at 10,000 entries and cleared when full. Projects with more modules than that kept clearing it, so every recorded hook recomputed the id normalization (including path.relative for dependencies) on the hot path.
  2. The panel's module list blocked the event loop. With the panel open, each edit triggers about two get-modules-list queries (one from the HMR update, one after the follow-up requests settle). Each query rebuilt the whole list in one synchronous run, so Vite couldn't serve any request in the meantime: about 100 ms per query at 15,000 modules.

Changes

  • Raise the public module id cache cap from 10,000 to 100,000, and note that it has to stay well above the module count of large projects.
  • Cache the module list per environment. The store now exposes getChangeVersion(), which increases on every write that can change recorded modules (clearPendingLoadMetrics doesn't count). getModulesList returns the previous list until the version changes.
  • Build the list in slices, yielding to the event loop about every 4 ms, so a long rebuild no longer stalls Vite in one block.

Impact

Measured locally with a synthetic project (half of the modules under node_modules, 20 plugins), median of 3 runs.

With the panel open, per edit:

5,000 modules 15,000 modules
First query, main-thread time 18 → 23 ms (within noise) 104 → 61 ms
First query, longest stall 18 → 17 ms 104 → 35 ms
Second query 19 → 0.1 ms 100 → 0.1 ms
Total main-thread time per edit ~37 → ~23 ms ~204 → ~61 ms

Without the panel, cold-start transform overhead at 15,000 modules goes from +33% to +21% because the id cache keeps hitting. Smaller projects already fit in the old cap and are unchanged.

The id cache uses about 9 MB when completely full (100,000 entries, about 97 bytes each, measured as heap with the cache filled minus heap after clearing it). It only grows that large in large projects or very long sessions.

Copilot AI balanced review requested due to automatic review settings October 22, 2026 09:03

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

@vitejs/devtools-kit

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

@vitejs/devtools-oxc

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

@vitejs/devtools-rolldown

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

@vitejs/devtools-vite

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

@vitejs/devtools-vitest

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

commit: 1d51c55

@webfansplz
webfansplz force-pushed the perf/inspect-module-list branch from 287311d to 1d51c55 Compare October 23, 2026 04:03
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