GeezerVison is showing github.com — perf_hooks: reduce overhead of new resource timings · nodejs/node@42e49ec
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: benchmark/perf_hooks/resourcetiming.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -72,6 +72,6 @@ function main({ n, observe }) { | 72 | 72 | obs.observe({ entryTypes: [observe], buffered: true }); | 73 | 73 |
| 74 | 74 | bench.start(); | 75 | | - for (let i = 0; i < 1e5; i++) | | 75 | + for (let i = 0; i < n; i++) | 76 | 76 | test(); | 77 | 77 | } |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/perf/performance_entry.js +12-8Lines changed: 12 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -31,10 +31,18 @@ function isPerformanceEntry(obj) { | 31 | 31 | } | 32 | 32 |
| 33 | 33 | class PerformanceEntry { | 34 | | - constructor(skipThrowSymbol = undefined) { | | 34 | + constructor( | | 35 | + skipThrowSymbol = undefined, | | 36 | + name = undefined, | | 37 | + type = undefined, | | 38 | + start = undefined, | | 39 | + duration = undefined, | | 40 | + ) { | 35 | 41 | if (skipThrowSymbol !== kSkipThrow) { | 36 | 42 | throw new ERR_ILLEGAL_CONSTRUCTOR(); | 37 | 43 | } | | 44 | + | | 45 | + initPerformanceEntry(this, name, type, start, duration); | 38 | 46 | } | 39 | 47 |
| 40 | 48 | get name() { | @@ -94,11 +102,7 @@ function initPerformanceEntry(entry, name, type, start, duration) { | 94 | 102 | } | 95 | 103 |
| 96 | 104 | function createPerformanceEntry(name, type, start, duration) { | 97 | | - const entry = new PerformanceEntry(kSkipThrow); | 98 | | - | 99 | | - initPerformanceEntry(entry, name, type, start, duration); | 100 | | - | 101 | | - return entry; | | 105 | + return new PerformanceEntry(kSkipThrow, name, type, start, duration); | 102 | 106 | } | 103 | 107 |
| 104 | 108 | /** | @@ -123,9 +127,8 @@ class PerformanceNodeEntry extends PerformanceEntry { | 123 | 127 | } | 124 | 128 |
| 125 | 129 | function createPerformanceNodeEntry(name, type, start, duration, detail) { | 126 | | - const entry = new PerformanceNodeEntry(kSkipThrow); | | 130 | + const entry = new PerformanceNodeEntry(kSkipThrow, name, type, start, duration); | 127 | 131 |
| 128 | | - initPerformanceEntry(entry, name, type, start, duration); | 129 | 132 | entry[kDetail] = detail; | 130 | 133 |
| 131 | 134 | return entry; | @@ -138,4 +141,5 @@ module.exports = { | 138 | 141 | isPerformanceEntry, | 139 | 142 | PerformanceNodeEntry, | 140 | 143 | createPerformanceNodeEntry, | | 144 | + kSkipThrow, | 141 | 145 | }; |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/perf/resource_timing.js +20-18Lines changed: 20 additions & 18 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 |
| 4 | 4 | const { | 5 | 5 | ObjectDefineProperties, | 6 | | - ObjectSetPrototypeOf, | 7 | | - ReflectConstruct, | 8 | 6 | Symbol, | 9 | 7 | SymbolToStringTag, | 10 | 8 | } = primordials; | 11 | | -const { initPerformanceEntry, PerformanceEntry } = require('internal/perf/performance_entry'); | 12 | | -const assert = require('internal/assert'); | 13 | | -const { enqueue, bufferResourceTiming } = require('internal/perf/observe'); | 14 | 9 | const { | 15 | 10 | codes: { | 16 | 11 | ERR_ILLEGAL_CONSTRUCTOR, | 17 | 12 | }, | 18 | 13 | } = require('internal/errors'); | | 14 | +const { PerformanceEntry, kSkipThrow } = require('internal/perf/performance_entry'); | | 15 | +const assert = require('internal/assert'); | | 16 | +const { enqueue, bufferResourceTiming } = require('internal/perf/observe'); | 19 | 17 | const { validateInternalField } = require('internal/validators'); | 20 | 18 | const { kEnumerableProperty } = require('internal/util'); | 21 | 19 |
| @@ -25,8 +23,12 @@ const kTimingInfo = Symbol('kTimingInfo'); | 25 | 23 | const kInitiatorType = Symbol('kInitiatorType'); | 26 | 24 |
| 27 | 25 | class PerformanceResourceTiming extends PerformanceEntry { | 28 | | - constructor() { | 29 | | - throw new ERR_ILLEGAL_CONSTRUCTOR(); | | 26 | + constructor(skipThrowSymbol = undefined, name = undefined, type = undefined) { | | 27 | + if (skipThrowSymbol !== kSkipThrow) { | | 28 | + throw new ERR_ILLEGAL_CONSTRUCTOR(); | | 29 | + } | | 30 | + | | 31 | + super(skipThrowSymbol, name, type); | 30 | 32 | } | 31 | 33 |
| 32 | 34 | get name() { | @@ -189,16 +191,17 @@ ObjectDefineProperties(PerformanceResourceTiming.prototype, { | 189 | 191 | }); | 190 | 192 |
| 191 | 193 | function createPerformanceResourceTiming(requestedUrl, initiatorType, timingInfo, cacheMode = '') { | 192 | | - return ReflectConstruct(function PerformanceResourceTiming() { | 193 | | - initPerformanceEntry(this, requestedUrl, 'resource'); | 194 | | - this[kInitiatorType] = initiatorType; | 195 | | - this[kRequestedUrl] = requestedUrl; | 196 | | - // https://fetch.spec.whatwg.org/#fetch-timing-info | 197 | | - // This class is using timingInfo assuming it's already validated. | 198 | | - // The spec doesn't say to validate it in the class construction. | 199 | | - this[kTimingInfo] = timingInfo; | 200 | | - this[kCacheMode] = cacheMode; | 201 | | - }, [], PerformanceResourceTiming); | | 194 | + const resourceTiming = new PerformanceResourceTiming(kSkipThrow, requestedUrl, 'resource'); | | 195 | + | | 196 | + resourceTiming[kInitiatorType] = initiatorType; | | 197 | + resourceTiming[kRequestedUrl] = requestedUrl; | | 198 | + // https://fetch.spec.whatwg.org/#fetch-timing-info | | 199 | + // This class is using timingInfo assuming it's already validated. | | 200 | + // The spec doesn't say to validate it in the class construction. | | 201 | + resourceTiming[kTimingInfo] = timingInfo; | | 202 | + resourceTiming[kCacheMode] = cacheMode; | | 203 | + | | 204 | + return resourceTiming; | 202 | 205 | } | 203 | 206 |
| 204 | 207 | // https://w3c.github.io/resource-timing/#dfn-mark-resource-timing | @@ -221,7 +224,6 @@ function markResourceTiming( | 221 | 224 | cacheMode, | 222 | 225 | ); | 223 | 226 |
| 224 | | - ObjectSetPrototypeOf(resource, PerformanceResourceTiming.prototype); | 225 | 227 | enqueue(resource); | 226 | 228 | bufferResourceTiming(resource); | 227 | 229 | return resource; | |
|