Repository navigation
perf(kit): drop hook events early and measure messages without copies - #1206
Merged
Merged
Conversation
- Return at the hook when no client is attached, before building the event. App lifecycle, plugin setup, and Vapor child tracking still run. - Cache whether an app belongs to DevTools itself once it is mounted. - Count UTF-8 bytes directly instead of encoding a copy, serialize tree patch events once, and reuse the size of keyed events that replace their entry.
✅ Deploy Preview for vue-devtools-docs canceled.
|
commit: |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the DevTools overhead reductions.
No open issues 🎉
What changed in this PR
Reduces shared DevTools kit overhead while collection is inactive and when measuring outgoing messages.
Changes:
- Drops inactive hook events before normalization while preserving lifecycle and Vapor tracking.
- Caches hidden-app detection after mount.
- Counts UTF-8 bytes without encoded copies and reuses tree-event measurements.
| File | Description |
|---|---|
tests/unit/rpc/event-buffer.test.ts |
Checks byte counts against TextEncoder. |
tests/integration/runtime/inactive-collection-hook.test.ts |
Covers inactive collection, lifecycle handling, and hidden apps. |
packages/kit/src/runtime/components.ts |
Uses shared message measurement for component metadata. |
packages/kit/src/rpc/event-buffer.ts |
Avoids encoding copies and reuses event-size calculations. |
packages/kit/src/hook/normalize.ts |
Caches hidden-app detection after mount. |
packages/kit/src/hook/install.ts |
Skips normalization for inactive collection events. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Vue calls the DevTools hook on every component render, add, remove, and emit, even while no DevTools panel is open. Before this PR, the kit built a full runtime event for each call and only then dropped it, so apps paid for DevTools they were not using. With a panel open, every outgoing message was serialized and then copied into a
TextEncoderbuffer just to measure its size. Tree patch events were serialized three times.receivedEventsanddroppedEventsnow also count events from unregistered or hidden apps while inactive._instanceor_containeryet, so nothing is cached.TextEncoder. Tree patch events are serialized once, and the result gives both the event's own size and its size when merged into a buffered batch. Keyed events that replace their buffered entry reuse their measured size.Results
On a local benchmark (not included): Vue 3.5 in happy-dom with 5,000 components, before and after runs interleaved:
component:updatedhook calls with DevTools closed: ~8.2 ms → ~2.1 msTesting
inactive-collection-hook.test.ts: with real Vue components, events are dropped while inactive and the current tree is read after a client connects; apps still register and unregister while inactive; apps hidden bydevtools.hideor mounted in avite-devtools-*shadow root stay hidden from mount onward. Breaking the cache or the lifecycle passthrough makes these tests fail.event-buffer.test.ts: byte counts matchTextEncoderfor every UTF-8 width and for lone surrogates. The existing legacy-equivalence tests still pass.playground/basicwith the panel opened from an iframe: routing with the panel closed and then opening it, live tree patches, state refresh, timeline, and Pinia. The flow had no regressions compared withmain.pnpm lint && pnpm test && pnpm typecheck: pass (84 files / 552 tests). The Vite and Chrome smoke tests pass.