From 798a6edddff79af461c80ceabba88559ca4c1ebc Mon Sep 17 00:00:00 2001 From: Chengzhong Wu Date: Sun, 21 Aug 2022 10:43:39 +0800 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. PR-URL: https://github.com/nodejs/node/pull/44220 Reviewed-By: Rafael Gonzaga --- doc/api/perf_hooks.md | 23 ++++ 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, 339 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 69c27310944db9..f59e78eb263840 100644 --- a/doc/api/perf_hooks.md +++ b/doc/api/perf_hooks.md @@ -312,6 +312,17 @@ 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. + +By default the max buffer size is set to 250. + ### `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`