Conversation
Observing the same entry type more than once on a PerformanceObserver,
through repeated `observe({ type })` calls or duplicates in
`entryTypes`, incremented the internal observer count each time, while
`disconnect()` decremented it only once per observed type. The counts
never returned to zero, so GC tracking stayed installed, and entries
for types such as `'http'` and `'dns'` kept being created after all
observers had disconnected.
Count each entry type at most once per observer.
Assisted-by: OpenCode
Signed-off-by: James M Snell <jasnell@gmail.com>
Whether the V8 GC callbacks used for `'gc'` performance entries were installed was tracked by a boolean in JavaScript, separately from the native state, and the two could get out of sync. After deserializing a user-land snapshot built while a `'gc'` PerformanceObserver was active, the boolean claimed the callbacks were installed, although V8 GC callbacks do not survive a snapshot. Observing `'gc'` again did not install them, and disconnecting removed callbacks that had never been registered, crashing the process. Track the installation state in `PerformanceState` instead, and replace the install and remove bindings with a single idempotent `updateGarbageCollectionTracking()` binding, which registers the callbacks if and only if there are `'gc'` observers. Assisted-by: OpenCode Signed-off-by: James M Snell <jasnell@gmail.com>
V8 GC callbacks do not survive a snapshot, so a `'gc'` PerformanceObserver that was active while building a user-land snapshot received no entries after deserialization, unless another `'gc'` observer was created. When `'gc'` is observed while building a snapshot, add a deserialize callback that registers the GC callbacks again if `'gc'` observers are still active. Assisted-by: OpenCode Signed-off-by: James M Snell <jasnell@gmail.com>
Collaborator
|
Review requested:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #66097 +/- ##
==========================================
- Coverage 90.27% 90.27% -0.01%
==========================================
Files 790 790
Lines 271591 271616 +25
Branches 51829 51835 +6
==========================================
+ Hits 245185 245197 +12
- Misses 16914 16929 +15
+ Partials 9492 9490 -2
🚀 New features to boost your workflow:
|
meixg
approved these changes
Sep 18, 2026
This comment was marked as outdated.
This comment was marked as outdated.
Collaborator
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.
PerformanceObservercounts could get out of sync. GC callback handling, in particular, could get out of sync when serializing/deserializing a snapshot, leading to a segfault.