Repository navigation
src: remove GCProfiler callbacks in stop() - #67799
Open
yohannesjoya wants to merge 1 commit into
Open
yohannesjoya wants to merge 1 commit into
yohannesjoya wants to merge 1 commit into
Conversation
GCProfiler::Stop() returned the profile but left the GC prologue and epilogue callbacks registered. They were only removed by the destructor, which runs when the binding object is collected. If the object had been promoted, that waited for the next mark-compact, and until then every collection called SetHeapStatistics() twice per stopped profiler and appended the result to a stream that is never read again. Code that starts and stops profilers repeatedly got slower and used more memory. Remove the callbacks in Stop(), and only remove them in the destructor if the profiler is still running. Fixes: nodejs#67790 Co-authored-by: Marcus Ording <11672035+snovader@users.noreply.github.com> Signed-off-by: Yohannes Desta <yohannesdestagebru10@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #67799 +/- ##
==========================================
- Coverage 92.99% 90.49% -2.51%
==========================================
Files 428 805 +377
Lines 195633 285820 +90187
Branches 30281 55173 +24892
==========================================
+ Hits 181937 258654 +76717
- Misses 13369 17255 +3886
- Partials 327 9911 +9584
🚀 New features to boost your workflow:
|
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.
GCProfiler::Stop()returned the profile but left the GC prologue and epilogue callbacks registered. Only the destructor removed them, and it runs when the binding object is collected. If the object had been promoted, that waits for the next mark-compact, and until then every collection callsSetHeapStatistics()twice per stopped profiler and appends the result to a stream nothing reads again.This removes the callbacks in
Stop(), and the destructor now only removes them if the profiler is still running. V8'sGCCallbacks::Remove()expects the callback to be registered, so they mustn't be removed twice. The fix is the one @snovader suggested in the issue, so they're co-author.Fixes: #67790
With the reproduction from the issue (100 start/stop cycles), allocation went from ~540 to ~2250 ns per call and RSS from 60 to 319 MB on main. With this change it stays at ~470 ns and 85 MB.
The effect is only visible as GC cost and native memory, so the new test doesn't time anything. It checks that stopping one profiler leaves another running profiler's callbacks in place, and that collecting stopped profilers afterwards doesn't crash.
tools/test.py parallel/test-v8-*passes locally (3 repeats), as domake format-cppand cpplint.AI disclosure: I used an AI assistant to help write the test and this description. I reproduced the issue, reviewed the change and ran the tests above myself.