[webrtc-stats] Don't expose so many RTCCodecStats! (#662)

henbos has just created a new issue for https://github.com/w3c/webrtc-stats:

== Don't expose so many RTCCodecStats! ==
We create an awful lot of `codec` stats objects. Every PT is listed for every m= section. And they are listed for both inbound and outbound direction, so you get all of them twice usually.

In a 50 participant Google Meet call I observed 872 `codec` stats objects, several KB worth of data.

## Performance / bloat issues

This is bad for `getStats()` performance due so many objects being created on the both C++ heap and the V8 heap and all the string copies this entails. Every `DOMString` in the dictionary is copied from an `RTCStatsMember<std::string>` which is copied from lower layers. Copies and object creation does not just happen initially when the report is created, but also every time you iterate the `RTCStatsReport` (which an app likely does a few times). Because of WebIDL dictionaries being passed-by-value, copies and object creation happens every time you iterate, even if you've seen that `codec` before.

The legacy getStats() is more performant than the modern getStats(), and this may help explain why.

This also bloats the report so you typically have to filter them out on manual inspection. `chrome://webrtc-internals/` chooses [not to list them](https://source.chromium.org/chromium/chromium/src/+/main:content/browser/webrtc/resources/stats_table.js;l=35;drc=ccc4b863a4a94811a24a4bbdb150b9b9dddf14c9) because they occlude the page and the rendering is unable to keep up if we include them all.

## This is not even useful

While useful to know what codec you are currently using, it is NOT useful to know every possible combination of PT on every m= section.
- If you wanted to know about codec capabilities, you'd use `RTCRtpSender/RTCRtpReceiver.getCapabilties().codecs`, not `getStats()`.
- If you wanted to inspect the SDP, you'd use `pc.localDescription` or `pc.remoteDescription`, which contains the same information already.

## Proposal

Let's only create `RTCCodecStats` objects representing what is _currently_ in use by `RTCOutboundRtpStreamStats`/`RTCInboundRtpStreamStats`. If it's not referenced by a `codecId`, it doesn't exist.


Please view or discuss this issue at https://github.com/w3c/webrtc-stats/issues/662 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Wednesday, 31 August 2022 08:35:32 UTC