summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2019-02-01 01:04:44 +0800
committerAnna Henningsen <anna@addaleax.net>2019-02-06 20:02:59 +0100
commit475c43c1b006e186036817c364dfc24a4d12c44f (patch)
treedbbc5df0bdc8e78c034be9402b62f23db64b776e /lib
parentcc5de5a5cc08551c54a2c1c40c05aa934d2156eb (diff)
downloadandroid-node-v8-475c43c1b006e186036817c364dfc24a4d12c44f.tar.gz
android-node-v8-475c43c1b006e186036817c364dfc24a4d12c44f.tar.bz2
android-node-v8-475c43c1b006e186036817c364dfc24a4d12c44f.zip
perf_hooks: only enable GC tracking when it's requested
Previously a GC prologue callback and a GC epilogue callback are always unconditionally enabled during bootstrap when the `performance` binding is loaded, even when the user does not use the performance timeline API to enable GC tracking. This patch makes the callback addition conditional and only enables them when the user explicitly requests `observer.observe(['gc'])` to avoid the overhead. PR-URL: https://github.com/nodejs/node/pull/25853 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/perf_hooks.js10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/perf_hooks.js b/lib/perf_hooks.js
index cb1640ef9b..583ffb56ca 100644
--- a/lib/perf_hooks.js
+++ b/lib/perf_hooks.js
@@ -11,7 +11,8 @@ const {
timeOrigin,
timeOriginTimestamp,
timerify,
- constants
+ constants,
+ setupGarbageCollectionTracking
} = internalBinding('performance');
const {
@@ -273,6 +274,8 @@ class PerformanceObserverEntryList {
}
}
+let gcTrackingIsEnabled = false;
+
class PerformanceObserver extends AsyncResource {
constructor(callback) {
if (typeof callback !== 'function') {
@@ -334,6 +337,11 @@ class PerformanceObserver extends AsyncResource {
if (entryTypes.length === 0) {
throw new errors.ERR_VALID_PERFORMANCE_ENTRY_TYPE();
}
+ if (entryTypes.includes(NODE_PERFORMANCE_ENTRY_TYPE_GC) &&
+ !gcTrackingIsEnabled) {
+ setupGarbageCollectionTracking();
+ gcTrackingIsEnabled = true;
+ }
this.disconnect();
this[kBuffer][kEntries] = [];
L.init(this[kBuffer][kEntries]);