Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b9fd240

Browse filesBrowse files
theanarkhruyadorno
authored andcommitted
perf_hooks: fix gc elapsed time
PR-URL: #44058 Refs: #44046 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 721639a commit b9fd240
Copy full SHA for b9fd240

File tree

Expand file treeCollapse file tree

2 files changed

+15
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+15
-1
lines changed
Open diff view settings
Collapse file

‎src/node_perf.cc‎

Copy file name to clipboardExpand all lines: src/node_perf.cc
+14-1Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,13 @@ void MarkGarbageCollectionStart(
118118
GCCallbackFlags flags,
119119
void* data) {
120120
Environment* env = static_cast<Environment*>(data);
121+
// Prevent gc callback from reentering with different type
122+
// See https://github.com/nodejs/node/issues/44046
123+
if (env->performance_state()->current_gc_type != 0) {
124+
return;
125+
}
121126
env->performance_state()->performance_last_gc_start_mark = PERFORMANCE_NOW();
127+
env->performance_state()->current_gc_type = type;
122128
}
123129

124130
MaybeLocal<Object> GCPerformanceEntryTraits::GetDetails(
@@ -155,6 +161,10 @@ void MarkGarbageCollectionEnd(
155161
void* data) {
156162
Environment* env = static_cast<Environment*>(data);
157163
PerformanceState* state = env->performance_state();
164+
if (type != state->current_gc_type) {
165+
return;
166+
}
167+
env->performance_state()->current_gc_type = 0;
158168
// If no one is listening to gc performance entries, do not create them.
159169
if (LIKELY(!state->observers[NODE_PERFORMANCE_ENTRY_TYPE_GC]))
160170
return;
@@ -179,14 +189,17 @@ void MarkGarbageCollectionEnd(
179189

180190
void GarbageCollectionCleanupHook(void* data) {
181191
Environment* env = static_cast<Environment*>(data);
192+
// Reset current_gc_type to 0
193+
env->performance_state()->current_gc_type = 0;
182194
env->isolate()->RemoveGCPrologueCallback(MarkGarbageCollectionStart, data);
183195
env->isolate()->RemoveGCEpilogueCallback(MarkGarbageCollectionEnd, data);
184196
}
185197

186198
static void InstallGarbageCollectionTracking(
187199
const FunctionCallbackInfo<Value>& args) {
188200
Environment* env = Environment::GetCurrent(args);
189-
201+
// Reset current_gc_type to 0
202+
env->performance_state()->current_gc_type = 0;
190203
env->isolate()->AddGCPrologueCallback(MarkGarbageCollectionStart,
191204
static_cast<void*>(env));
192205
env->isolate()->AddGCEpilogueCallback(MarkGarbageCollectionEnd,
Collapse file

‎src/node_perf_common.h‎

Copy file name to clipboardExpand all lines: src/node_perf_common.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class PerformanceState {
7171
AliasedUint32Array observers;
7272

7373
uint64_t performance_last_gc_start_mark = 0;
74+
uint16_t current_gc_type = 0;
7475

7576
void Mark(enum PerformanceMilestone milestone,
7677
uint64_t ts = PERFORMANCE_NOW());

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.