From 33fc8997f8e5c85be340659064c078a0b589ee67 Mon Sep 17 00:00:00 2001 From: Robin Date: Tue, 4 Aug 2026 19:21:33 +0200 Subject: [PATCH] Performance: Use a shared timer for polling RTP stats This is now only relevant in case the user has enabled the developer option to show advanced media statistics, but still an easy performance fix. --- src/state/media/observeRtpStreamStats.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/state/media/observeRtpStreamStats.ts b/src/state/media/observeRtpStreamStats.ts index d1640382a..afb0da62d 100644 --- a/src/state/media/observeRtpStreamStats.ts +++ b/src/state/media/observeRtpStreamStats.ts @@ -19,10 +19,15 @@ import { startWith, switchMap, map, + share, } from "rxjs"; import { observeTrackReference$ } from "../observeTrackReference"; +// Use a shared timer for all the stats observers so that we don't clog up the +// event loop with hundreds of timers in large calls +const refreshStats$ = interval(1000).pipe(share()); + export function observeRtpStreamStats$( participant: Participant, source: Track.Source, @@ -32,7 +37,7 @@ export function observeRtpStreamStats$( > { return combineLatest([ observeTrackReference$(participant, source), - interval(1000).pipe(startWith(0)), + refreshStats$.pipe(startWith(0)), ]).pipe( switchMap(async ([trackReference]) => { const track = trackReference?.publication?.track;