From 6ef3a937c520be074627c89c3239df4de407e5fa Mon Sep 17 00:00:00 2001 From: Chengzhong Wu Date: Fri, 12 Aug 2022 03:55:15 +0000 Subject: [PATCH] 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. --- doc/api/perf_hooks.md | 18 +++ lib/internal/bootstrap/browser.js | 4 +- lib/internal/perf/observe.js | 84 +++++++++++- lib/internal/perf/performance.js | 23 +++- lib/internal/perf/resource_timing.js | 3 +- lib/internal/perf/usertiming.js | 4 +- lib/perf_hooks.js | 8 +- test/common/index.js | 3 + ...st-performance-resourcetimingbufferfull.js | 128 ++++++++++++++++++ ...st-performance-resourcetimingbuffersize.js | 70 ++++++++++ 10 files changed, 334 insertions(+), 11 deletions(-) create mode 100644 test/parallel/test-performance-resourcetimingbufferfull.js create mode 100644 test/parallel/test-performance-resourcetimingbuffersize.js diff --git a/doc/api/perf_hooks.md b/doc/api/perf_hooks.md index bb5648f0a74439..7771af74683806 100644 --- a/doc/api/perf_hooks.md +++ b/doc/api/perf_hooks.md @@ -308,6 +308,15 @@ added: v8.5.0 Returns the current high resolution millisecond timestamp, where 0 represents the start of the current `node` process. +### `performance.setResourceTimingBufferSize(maxSize)` + + + +Sets the global performance resource timing buffer size to the specified number +of "resource" type performance entry objects. + ### `performance.timeOrigin` + +The `'resourcetimingbufferfull'` event is fired when the global performance +resource timing buffer is full. + ## Class: `PerformanceEntry`