You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
net: Subscriber.runGroup creates a StreamError(Cancel) with a captured stack for every completed group, 47-50 per second per audio track #4779
We profiled the receive path of a viewer subscribed to many audio tracks (one-frame groups, 47-50 groups per second per track). Most of the per-group cost we found is already on release: #4316, #4267 and #4454 (and #4226 on main). What remains: after every cleanly finished group Subscriber.runGroup calls stream.stop(new StreamError(StreamCode.Cancel, { message: "cancel" })), which allocates an Error with a captured stack per group, and Reader.stop then converts it again. For an Opus track that is 47-50 error objects per second per track.
Versions
@moq/net 0.4.1 (npm). The same code is at moq-relay-v0.17.0 and on main (83ce47f). The profile below was taken on 0.4.1 with the #4321 change applied by hand, and without #4316, #4267 and #4454, so the share may be different with them.
Steps to reproduce
Subscribe a browser viewer to N audio tracks published by @moq/publish (one Opus frame per group) and take a Chrome performance profile of its main thread; look for StreamError / RemoteError construction under runGroup and stop.
Expected
The routine cancel of a finished group does not allocate per group: a preallocated error or a code-only path to cancel(...). The code already avoids capturing stacks on hot paths elsewhere (Short in js/net/src/stream.ts:491-493: "Not an Error: it ends every chunk, so it must not capture a stack").
Actual
Viewer with 8 video tiles and 12 or 30 microphone tracks (software-rendered Chromium on a test server, QUIC, 60 s window), self time as a share of the main thread: StreamError / RemoteError construction in runGroup and its stop: 0.55% with 12 microphones, 0.95% with 30. @moq/net 0.3.5 had no such entry. The same profile with 30 microphones has the main thread 97.7% busy on 0.3.5 and 98.2% on 0.4.1 (both saturated), so every per-group cost counts.
Where in the code
js/net/src/lite/subscriber.ts:1074 (runGroup: after readFrames, and :1064 before the timescale is known). :1107 on main, :999 in npm 0.4.1.
js/net/src/stream.ts:469-471 (Reader.stop passes the reason through withCode, :24-29).
Activity