Skip to content

perf(vite): speed up inspect payload allocation - #621

Merged
webfansplz merged 1 commit into
mainfrom
perf/inspect-payload-free-ranges
Oct 23, 2026
Merged

webfansplz merged 1 commit into
mainfrom
perf/inspect-payload-free-ranges

Conversation

@webfansplz

Copy link
Copy Markdown
Member

Summary

When modules are invalidated, the inspect store frees their space in the payload archive, and new records reuse those gaps. The free-space list was handled with full passes: every reclaim pushed the freed ranges and re-sorted and re-merged the whole list, and every allocation scanned the whole list for the best fit. The more edits a session went through, the more fragmented the archive became and the longer the list grew, so each edit got a little slower, with no upper bound. This work runs on the main thread right after an edit.

This PR keeps the cost of each reclaim and allocation independent of how fragmented the archive is. Allocation results are unchanged.

Changes

  • Keep free ranges sorted by offset. Reclaim inserts each range with a binary search and merges it only with its neighbors, instead of re-sorting and re-merging the whole list.
  • Bucket free ranges by size (powers of two). Allocation only looks at buckets large enough for the request, instead of scanning every free range.
  • The allocation rule stays the same: the smallest free range that fits, the lowest offset among equal sizes, split from the front.

Impact

Measured locally with a synthetic project (5,000 modules × 200 lines, half under node_modules, 20 plugins): 50 consecutive edits, each invalidating and re-requesting a different set of 200 modules. Median of 3 runs:

First 5 edits Last 5 edits
Without inspect 33–34 ms 35–37 ms
With inspect, before 66 ms 91 ms (+38%)
With inspect, after 68 ms 66 ms

After 50 edits the archive had about 4,400 free ranges. A CPU profile of the last edits showed about 22 ms per edit in allocate, mergeFreeRanges, and reclaim before this change, compared with about 3.5 ms on the first edit. Short sessions and small projects don't build up enough free ranges to show a difference; the gain shows up in long dev sessions with many edits.

Copilot AI balanced review requested due to automatic review settings October 22, 2026 06:24

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

@vitejs/devtools-kit

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

@vitejs/devtools-oxc

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

@vitejs/devtools-rolldown

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

@vitejs/devtools-vite

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

@vitejs/devtools-vitest

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

commit: 0a87339

@webfansplz
webfansplz merged commit f035a20 into main Oct 23, 2026
10 checks passed
@webfansplz
webfansplz deleted the perf/inspect-payload-free-ranges branch October 23, 2026 03:55
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