Export GetCodecMap for efficient payload type lookups#248
Export GetCodecMap for efficient payload type lookups#248
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #248 +/- ##
=======================================
Coverage 97.43% 97.43%
=======================================
Files 12 12
Lines 1405 1405
=======================================
Hits 1369 1369
Misses 19 19
Partials 17 17
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Rename buildCodecMap to GetCodecMap so callers can build the codec map once and reuse it for multiple payload type lookups. This is needed by pion/webrtc's codecsFromMediaDescription (sdp.go:1101), which calls GetCodecForPayloadType in a loop (sdp.go:1112), rebuilding the full codec map on every iteration. With GetCodecMap exported, webrtc can build the map once and do direct lookups.
5e27285 to
5014502
Compare
|
Can we cache codec map inside the library instead, I think this was the original plan when it got merged, I'm down for full api change if we have to and a major release but sdp users shouldn't have to implement the helpers themself. |
|
With the way the code is structured right now, the only way to implement your suggestion is to add lazy caching to buildCodecMap. I was thinking that it can be done when SDP is parsed, but turns out webrtc doesn't do any parsing: Is this approach ok? That would also introduce private fields in |
|
@JoTurk small nudge. This is a benign change, but it does make a difference in thundering herd scenarios. |
|
What if we merge this now, and plan for a next major release where we control the constructors and the mutation calls so we can have internal map? |
Description
Rename
buildCodecMaptoGetCodecMapso callers can build the codec map once and reuse it for multiple payload type lookups. CPU overhead manifests itself in thundering herd scenario when we're creating new peer connections at a very high TPS rate.This is needed by pion/webrtc's
codecsFromMediaDescription (sdp.go:1101), which currently callsGetCodecForPayloadTypein a loop (sdp.go:1112), rebuilding the full codec map on every iteration. With GetCodecMap exported, webrtc can build the map once and do direct lookups instead.There will be webrtc integration patch in webrtc. We should bump minor SDP version to avoid compatibility issues.