Optimize set of registered SSRCs in RTCPReceiver
In highly loaded media servers, RTCPReceiver's use of std::set
attributes to ~0.87% CPU. It's mostly ::find and the [] operator and the
assignment operator.
* Removed locking of a mutex in `TriggerCallbacksFromRtcpPacket``
as it copied members that were already const.
* Switched the use of std::set for the list of registered local SSRCs
to an absl::InlinedVector, as the set is very small and it's not
expected that any more complicated container would be faster than a
linear search within a cache line.
Bug: webrtc:12689
Change-Id: I734578c22eeca2d9ba89fef77ecc689b72624567
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/216322
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33849}
diff --git a/modules/rtp_rtcp/source/rtcp_receiver.h b/modules/rtp_rtcp/source/rtcp_receiver.h
index 7b0f38b..a9f602f 100644
--- a/modules/rtp_rtcp/source/rtcp_receiver.h
+++ b/modules/rtp_rtcp/source/rtcp_receiver.h
@@ -124,6 +124,23 @@
void NotifyTmmbrUpdated();
private:
+ // A lightweight inlined set of local SSRCs.
+ class RegisteredSsrcs {
+ public:
+ static constexpr size_t kMaxSsrcs = 3;
+ // Initializes the set of registered local SSRCS by extracting them from the
+ // provided `config`.
+ explicit RegisteredSsrcs(const RtpRtcpInterface::Configuration& config);
+
+ // Indicates if `ssrc` is in the set of registered local SSRCs.
+ bool contains(uint32_t ssrc) const {
+ return absl::c_linear_search(ssrcs_, ssrc);
+ }
+
+ private:
+ absl::InlinedVector<uint32_t, kMaxSsrcs> ssrcs_;
+ };
+
struct PacketInformation;
struct TmmbrInformation;
struct RrtrInformation;
@@ -229,7 +246,8 @@
const bool receiver_only_;
ModuleRtpRtcp* const rtp_rtcp_;
const uint32_t main_ssrc_;
- const std::set<uint32_t> registered_ssrcs_;
+ // The set of registered local SSRCs.
+ const RegisteredSsrcs registered_ssrcs_;
RtcpBandwidthObserver* const rtcp_bandwidth_observer_;
RtcpIntraFrameObserver* const rtcp_intra_frame_observer_;