From 0e38fba552291bca0264a7709a338352d18a9844 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 a56b1f232a1b06..f2d2041ee1b135 100644 --- a/doc/api/perf_hooks.md +++ b/doc/api/perf_hooks.md @@ -308,6 +308,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`