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}
This commit is contained in:
Victor Boivie
2021-04-27 10:33:58 +02:00
committed by WebRTC LUCI CQ
parent 723873b841
commit 306b1393cb
2 changed files with 43 additions and 32 deletions

View File

@ -124,6 +124,23 @@ class RTCPReceiver final {
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 @@ class RTCPReceiver final {
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_;