From e5c6de06254755dd8e03f23375b2ffcdd6a7a3f6 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 | 21 +++ 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, 337 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..27e1f573ba63e2 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. Adjust resource timing buffer size with +`performance.setResourceTimingBufferSize()` or clear the buffer with +`performance.clearResourceTimings()` in the event listener to allow +more entries to be added to the performance timeline buffer. + ## Class: `PerformanceEntry`