Skip to content

perf: use disk logs with in-memory metadata#400

Draft
webfansplz wants to merge 2 commits into
mainfrom
perf/inspect-vite
Draft

perf: use disk logs with in-memory metadata#400
webfansplz wants to merge 2 commits into
mainfrom
perf/inspect-vite

Conversation

@webfansplz

@webfansplz webfansplz commented Jul 12, 2026

Copy link
Copy Markdown
Member

Context

This PR updates the persistence approach after evaluating a database-backed replacement for the previous memory-based solution.

I first tried using a DB for both reading and writing runtime data, but found that Vite core generate data much faster than the DB can persist it. Under that write pressure, the DB approach becomes a bottleneck and is not viable for this use case.

After testing and comparing alternatives, this PR adopts disk logs with in-memory metadata instead. This keeps high-volume writes append-friendly on disk while allowing the runtime to maintain fast metadata access in memory, which better matches the data flow and performance profile of Vite core.

Benchmark

Compared perf/inspect-vite@012f72c (this PR) with main@67cf430 branch using 10,000 modules, 200 plugins, and 160,000 plugin calls. Results are medians from seven fresh Node.js processes using the production disk-backed storage path.

Results

Processing Time

Operation This branch main Change
Ingest all events 241.61 ms 137.31 ms 76.0% slower
Get modules list 79.37 ms 80.91 ms 1.9% faster
Get plugin metrics 7.06 ms 11.92 ms 40.8% faster
Get plugin details 14.52 ms 0.17 ms 85x slower
Get module transform info 1.00 ms 7.36 ms 86.4% faster

Ingestion throughput drops from 1.17M to 662K events/s. For this workload, the total ingestion cost increases by approximately 104 ms.

Memory

Metric This branch main Change
Incremental retained heap +28.05 MiB +80.76 MiB 65.3% lower
Incremental RSS after ingestion +69.63 MiB +100.86 MiB 31.0% lower
Incremental peak RSS +101.06 MiB +148.73 MiB 32.1% lower
Inspect archive size 109.92 MiB 0 MiB Stored on disk

Conclusion

  • The branch significantly reduces retained memory, especially JavaScript heap usage.
  • Event ingestion is slower, but the additional cost is approximately 104 ms for 160,000 calls.
  • Module and metrics queries improve, while plugin-details queries regress because they scan all stored calls.
  • Under bursty input, the unbounded write queue can temporarily reverse the RSS improvement. Queue backpressure or adaptive batching should be considered separately.

All runs returned the expected 10,000 modules, 200 plugin metrics, 800 calls for the selected plugin, and 13 transforms for the selected module.

Copilot AI review requested due to automatic review settings July 12, 2026 13:19
@webfansplz webfansplz marked this pull request as draft July 12, 2026 13:20
@pkg-pr-new

pkg-pr-new Bot commented Jul 12, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: bee29fc

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.

Pull request overview

This PR refactors the Vite inspect collector to persist large transform payloads and plugin-call logs to disk while keeping query/metadata in memory, reducing memory pressure and improving responsiveness during heavy transform activity.

Changes:

  • Introduces a disk-backed inspect store (payloads.bin + plugin-calls.bin) with batched, async persistence and invalidation-aware reclamation.
  • Updates inspect collection + RPC dump inputs to operate on async module ID enumeration and adds request-staleness tracking to avoid recording invalidated work.
  • Extends plugin-call data with graphModuleId resolution for more accurate UI linking, and adds a new structured diagnostic (VDT0003) + docs.

Reviewed changes

Copilot reviewed 22 out of 23 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pnpm-lock.yaml Updates tar dependency version in the lockfile.
packages/vite/src/node/rpc/functions/vite-resolve-id.ts Adjusts RPC dump input collection to await async module ID enumeration.
packages/vite/src/node/rpc/functions/vite-get-module-transform-info.ts Same async module ID enumeration change for transform-info RPC dump inputs.
packages/vite/src/node/inspect/utils.ts Removes raw from parsed errors and makes module ID enumeration async via environment APIs.
packages/vite/src/node/inspect/types.ts Adds optional graphModuleId on plugin-call records.
packages/vite/src/node/inspect/store/types.ts Defines the inspect store interfaces, batch stats, and persisted record shapes.
packages/vite/src/node/inspect/store/plugin-calls.ts Adds a binary plugin-call archive (memory or file-backed) with invalidation-aware slot reuse.
packages/vite/src/node/inspect/store/payload.ts Adds a payload archive (memory or file-backed) with range allocation + reclamation.
packages/vite/src/node/inspect/store/index.ts Implements the main queued/batched inspect store with flush/close semantics and metrics APIs.
packages/vite/src/node/inspect/server.ts Adds AsyncLocalStorage-based request tracking + smarter invalidation behavior.
packages/vite/src/node/inspect/plugins.ts Adds async plugin metrics/details powered by the new store and resolves graphModuleId.
packages/vite/src/node/inspect/plugin.ts Creates and manages on-disk inspect storage under Vite’s cache dir; wires stale-request checks.
packages/vite/src/node/inspect/module.ts Moves module list + module transform info logic into a dedicated helper module.
packages/vite/src/node/inspect/hijack.ts Skips recording transforms/loads/resolveIds for stale transform requests.
packages/vite/src/node/inspect/context.ts Refactors environment context to use the new async store-backed model.
packages/vite/src/node/diagnostics.ts Adds diagnostic code VDT0003 for inspect storage failures.
packages/vite/src/node/tests/inspect-server.test.ts Adds coverage for invalidation behavior and request-context staleness tracking.
packages/vite/src/node/tests/inspect-plugin.test.ts Adds coverage for plugin lifecycle closing of inspect storage.
packages/vite/src/node/tests/inspect-context.test.ts Updates/expands tests for async APIs, file-backed storage, batching, reuse, and GC behavior.
packages/vite/src/app/components/data/PluginDetailsTable.vue Uses graphModuleId (when available) for graph navigation links.
packages/vite/src/app/components/data/PluginDetailsLoader.vue Uses graphModuleId (when available) for graph navigation links in the tree view.
docs/errors/VDT0003.md Adds documentation for the new inspect storage diagnostic.
docs/errors/index.md Registers VDT0003 in the diagnostics index.
Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/vite/src/node/inspect/plugin.ts Outdated
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