From df6db01ff4bdbbdff3527c557cc6754ed1571335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Louren=C3=A7o?= Date: Sun, 1 Oct 2023 13:03:18 -0300 Subject: [PATCH] fixup! perf_hooks: reduce overhead of new user timings --- lib/internal/perf/observe.js | 8 ++++++-- lib/internal/perf/usertiming.js | 10 +++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/internal/perf/observe.js b/lib/internal/perf/observe.js index b97ae08402260a..ccc2d62de73218 100644 --- a/lib/internal/perf/observe.js +++ b/lib/internal/perf/observe.js @@ -171,9 +171,13 @@ function maybeIncrementObserverCount(type) { } } +const kSkipThrow = Symbol('kSkipThrow'); + class PerformanceObserverEntryList { - constructor() { - throw new ERR_ILLEGAL_CONSTRUCTOR(); + constructor(skipThrowSymbol = undefined) { + if (skipThrowSymbol !== kSkipThrow) { + throw new ERR_ILLEGAL_CONSTRUCTOR(); + } } getEntries() { diff --git a/lib/internal/perf/usertiming.js b/lib/internal/perf/usertiming.js index 63f4fa0e8874a0..ff417d94700550 100644 --- a/lib/internal/perf/usertiming.js +++ b/lib/internal/perf/usertiming.js @@ -66,17 +66,15 @@ function getMark(name) { return ts; } -const kEmptyArg = Symbol('kEmptyArg'); - class PerformanceMark extends PerformanceEntry { - constructor(name = kEmptyArg, options = undefined) { - if (name === kEmptyArg) { + constructor(name, options = undefined) { + if (arguments.length === 0) { throw new ERR_MISSING_ARGS('name'); } name = `${name}`; if (nodeTimingReadOnlyAttributes.has(name)) throw new ERR_INVALID_ARG_VALUE('name', name); - if (options !== undefined) { + if (options != null) { validateObject(options, 'options'); } const startTime = options?.startTime ?? now(); @@ -86,8 +84,6 @@ class PerformanceMark extends PerformanceEntry { markTimings.set(name, startTime); let detail = options?.detail; - // The usage of != is intentional, we want to skip structuredClone - // for both undefined and null detail = detail != null ? structuredClone(detail) : null;