-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf_hooks: add resourcetiming buffer limit
Add WebPerf API `performance.setResourceTimingBufferSize` and event `'resourcetimingbufferfull'` support. The resource timing entries are added to the global performance timeline buffer automatically when using fetch. If users are not proactively cleaning these events, it can grow without limit. Apply the https://www.w3.org/TR/timing-entrytypes-registry/ default resource timing buffer max size so that the buffer can be limited to not grow indefinitely.
- Loading branch information
1 parent
ec44403
commit 2579888
Showing
9 changed files
with
162 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
test/parallel/test-performance-resourcetimingbuffersize.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
const { performance } = require('perf_hooks'); | ||
|
||
const timingInfo = { | ||
startTime: 0, | ||
endTime: 0, | ||
finalServiceWorkerStartTime: 0, | ||
redirectStartTime: 0, | ||
redirectEndTime: 0, | ||
postRedirectStartTime: 0, | ||
finalConnectionTimingInfo: { | ||
domainLookupStartTime: 0, | ||
domainLookupEndTime: 0, | ||
connectionStartTime: 0, | ||
connectionEndTime: 0, | ||
secureConnectionStartTime: 0, | ||
ALPNNegotiatedProtocol: 0, | ||
}, | ||
finalNetworkRequestStartTime: 0, | ||
finalNetworkResponseStartTime: 0, | ||
encodedBodySize: 0, | ||
decodedBodySize: 0, | ||
}; | ||
const requestedUrl = 'https://nodejs.org'; | ||
const initiatorType = ''; | ||
const cacheMode = ''; | ||
|
||
performance.addEventListener('resourcetimingbufferfull', common.mustCall((event) => { | ||
assert.strictEqual(event.type, 'resourcetimingbufferfull'); | ||
}, 2)); | ||
|
||
performance.setResourceTimingBufferSize(1); | ||
performance.markResourceTiming(timingInfo, requestedUrl, initiatorType, globalThis, cacheMode); | ||
// Trigger a resourcetimingbufferfull event. | ||
performance.markResourceTiming(timingInfo, requestedUrl, initiatorType, globalThis, cacheMode); | ||
assert.strictEqual(performance.getEntriesByType('resource').length, 1); | ||
|
||
// Apply a new buffer size limit | ||
performance.setResourceTimingBufferSize(0); | ||
// Buffer is not cleared on `performance.setResourceTimingBufferSize`. | ||
assert.strictEqual(performance.getEntriesByType('resource').length, 1); | ||
|
||
performance.clearResourceTimings(); | ||
assert.strictEqual(performance.getEntriesByType('resource').length, 0); | ||
// Trigger a resourcetimingbufferfull event. | ||
performance.markResourceTiming(timingInfo, requestedUrl, initiatorType, globalThis, cacheMode); | ||
// New entry is not added to the global buffer. | ||
assert.strictEqual(performance.getEntriesByType('resource').length, 0); | ||
|
||
// Apply a new buffer size limit | ||
performance.setResourceTimingBufferSize(1); | ||
performance.markResourceTiming(timingInfo, requestedUrl, initiatorType, globalThis, cacheMode); | ||
assert.strictEqual(performance.getEntriesByType('resource').length, 1); |