GeezerVison is showing github.com — perf_hooks: reduce overhead of new user timings · nodejs/node@e8f024b
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/perf/performance_entry.js +4-9Lines changed: 4 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -42,7 +42,10 @@ class PerformanceEntry { | 42 | 42 | throw new ERR_ILLEGAL_CONSTRUCTOR(); | 43 | 43 | } | 44 | 44 |
| 45 | | - initPerformanceEntry(this, name, type, start, duration); | | 45 | + this[kName] = name; | | 46 | + this[kEntryType] = type; | | 47 | + this[kStartTime] = start; | | 48 | + this[kDuration] = duration; | 46 | 49 | } | 47 | 50 |
| 48 | 51 | get name() { | @@ -94,13 +97,6 @@ ObjectDefineProperties(PerformanceEntry.prototype, { | 94 | 97 | toJSON: kEnumerableProperty, | 95 | 98 | }); | 96 | 99 |
| 97 | | -function initPerformanceEntry(entry, name, type, start, duration) { | 98 | | - entry[kName] = name; | 99 | | - entry[kEntryType] = type; | 100 | | - entry[kStartTime] = start; | 101 | | - entry[kDuration] = duration; | 102 | | -} | 103 | | - | 104 | 100 | function createPerformanceEntry(name, type, start, duration) { | 105 | 101 | return new PerformanceEntry(kSkipThrow, name, type, start, duration); | 106 | 102 | } | @@ -135,7 +131,6 @@ function createPerformanceNodeEntry(name, type, start, duration, detail) { | 135 | 131 | } | 136 | 132 |
| 137 | 133 | module.exports = { | 138 | | - initPerformanceEntry, | 139 | 134 | createPerformanceEntry, | 140 | 135 | PerformanceEntry, | 141 | 136 | isPerformanceEntry, | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/perf/usertiming.js +28-19Lines changed: 28 additions & 19 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 |
| 3 | 3 | const { | 4 | 4 | ObjectDefineProperties, | 5 | | - ObjectSetPrototypeOf, | 6 | 5 | SafeMap, | 7 | 6 | SafeSet, | 8 | 7 | SafeArrayIterator, | 9 | 8 | Symbol, | 10 | 9 | SymbolToStringTag, | 11 | | - ReflectConstruct, | 12 | 10 | } = primordials; | 13 | 11 |
| 14 | | -const { initPerformanceEntry, PerformanceEntry } = require('internal/perf/performance_entry'); | | 12 | +const { PerformanceEntry, kSkipThrow } = require('internal/perf/performance_entry'); | 15 | 13 | const { now } = require('internal/perf/utils'); | 16 | 14 | const { enqueue, bufferUserTiming } = require('internal/perf/observe'); | 17 | 15 | const nodeTiming = require('internal/perf/nodetiming'); | @@ -35,7 +33,6 @@ const { | 35 | 33 |
| 36 | 34 | const { structuredClone } = require('internal/structured_clone'); | 37 | 35 | const { | 38 | | - kEmptyObject, | 39 | 36 | lazyDOMException, | 40 | 37 | kEnumerableProperty, | 41 | 38 | } = require('internal/util'); | @@ -69,27 +66,29 @@ function getMark(name) { | 69 | 66 | return ts; | 70 | 67 | } | 71 | 68 |
| 72 | | -class PerformanceMark { | 73 | | - constructor(name, options = kEmptyObject) { | | 69 | +class PerformanceMark extends PerformanceEntry { | | 70 | + constructor(name, options = undefined) { | 74 | 71 | if (arguments.length === 0) { | 75 | 72 | throw new ERR_MISSING_ARGS('name'); | 76 | 73 | } | 77 | 74 | name = `${name}`; | 78 | | - options ??= kEmptyObject; | 79 | 75 | if (nodeTimingReadOnlyAttributes.has(name)) | 80 | 76 | throw new ERR_INVALID_ARG_VALUE('name', name); | 81 | | - validateObject(options, 'options'); | 82 | | - const startTime = options.startTime ?? now(); | | 77 | + if (options != null) { | | 78 | + validateObject(options, 'options'); | | 79 | + } | | 80 | + const startTime = options?.startTime ?? now(); | 83 | 81 | validateNumber(startTime, 'startTime'); | 84 | 82 | if (startTime < 0) | 85 | 83 | throw new ERR_PERFORMANCE_INVALID_TIMESTAMP(startTime); | 86 | 84 | markTimings.set(name, startTime); | 87 | 85 |
| 88 | | - let detail = options.detail; | | 86 | + let detail = options?.detail; | 89 | 87 | detail = detail != null ? | 90 | 88 | structuredClone(detail) : | 91 | 89 | null; | 92 | | - initPerformanceEntry(this, name, 'mark', startTime, 0); | | 90 | + | | 91 | + super(kSkipThrow, name, 'mark', startTime, 0); | 93 | 92 | this[kDetail] = detail; | 94 | 93 | } | 95 | 94 |
| @@ -108,8 +107,7 @@ class PerformanceMark { | 108 | 107 | }; | 109 | 108 | } | 110 | 109 | } | 111 | | -ObjectSetPrototypeOf(PerformanceMark, PerformanceEntry); | 112 | | -ObjectSetPrototypeOf(PerformanceMark.prototype, PerformanceEntry.prototype); | | 110 | + | 113 | 111 | ObjectDefineProperties(PerformanceMark.prototype, { | 114 | 112 | detail: kEnumerableProperty, | 115 | 113 | [SymbolToStringTag]: { | @@ -120,8 +118,18 @@ ObjectDefineProperties(PerformanceMark.prototype, { | 120 | 118 | }); | 121 | 119 |
| 122 | 120 | class PerformanceMeasure extends PerformanceEntry { | 123 | | - constructor() { | 124 | | - throw new ERR_ILLEGAL_CONSTRUCTOR(); | | 121 | + constructor( | | 122 | + skipThrowSymbol = undefined, | | 123 | + name = undefined, | | 124 | + type = undefined, | | 125 | + start = undefined, | | 126 | + duration = undefined, | | 127 | + ) { | | 128 | + if (skipThrowSymbol !== kSkipThrow) { | | 129 | + throw new ERR_ILLEGAL_CONSTRUCTOR(); | | 130 | + } | | 131 | + | | 132 | + super(skipThrowSymbol, name, type, start, duration); | 125 | 133 | } | 126 | 134 |
| 127 | 135 | get detail() { | @@ -139,10 +147,11 @@ ObjectDefineProperties(PerformanceMeasure.prototype, { | 139 | 147 | }); | 140 | 148 |
| 141 | 149 | function createPerformanceMeasure(name, start, duration, detail) { | 142 | | - return ReflectConstruct(function PerformanceMeasure() { | 143 | | - initPerformanceEntry(this, name, 'measure', start, duration); | 144 | | - this[kDetail] = detail; | 145 | | - }, [], PerformanceMeasure); | | 150 | + const measure = new PerformanceMeasure(kSkipThrow, name, 'measure', start, duration); | | 151 | + | | 152 | + measure[kDetail] = detail; | | 153 | + | | 154 | + return measure; | 146 | 155 | } | 147 | 156 |
| 148 | 157 | function mark(name, options) { | |
|