Use unordered_map in RTCPReceiver

In highly loaded media servers, RTCPReceiver's use of std::map
attributes to ~0.5% CPU. It's mostly ::find and the [] operator, and
they are all keyed by SSRC, which is an unordered data type. This makes
these maps suitable as unordered maps, as they have constant time
complexity for lookups.

Bug: webrtc:12689
Change-Id: I7b305e233fcbed0e452632946ab0de5ee66f8dda
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/216321
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33850}
This commit is contained in:
Victor Boivie
2021-04-27 10:24:01 +02:00
committed by WebRTC LUCI CQ
parent 306b1393cb
commit 0c563a42ec
2 changed files with 17 additions and 9 deletions

View File

@ -15,6 +15,7 @@
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#include "api/array_view.h"
@ -145,6 +146,11 @@ class RTCPReceiver final {
struct TmmbrInformation;
struct RrtrInformation;
struct LastFirStatus;
// TODO(boivie): `ReportBlockDataMap` and `ReportBlockMap` should be converted
// to std::unordered_map, but as there are too many tests that assume a
// specific order, it's not easily done.
// RTCP report blocks mapped by remote SSRC.
using ReportBlockDataMap = std::map<uint32_t, ReportBlockData>;
// RTCP report blocks map mapped by source SSRC.
@ -273,7 +279,7 @@ class RTCPReceiver final {
std::list<RrtrInformation> received_rrtrs_
RTC_GUARDED_BY(rtcp_receiver_lock_);
// Received RRTR information mapped by remote ssrc.
std::map<uint32_t, std::list<RrtrInformation>::iterator>
std::unordered_map<uint32_t, std::list<RrtrInformation>::iterator>
received_rrtrs_ssrc_it_ RTC_GUARDED_BY(rtcp_receiver_lock_);
// Estimated rtt, zero when there is no valid estimate.
@ -282,11 +288,11 @@ class RTCPReceiver final {
int64_t oldest_tmmbr_info_ms_ RTC_GUARDED_BY(rtcp_receiver_lock_);
// Mapped by remote ssrc.
std::map<uint32_t, TmmbrInformation> tmmbr_infos_
std::unordered_map<uint32_t, TmmbrInformation> tmmbr_infos_
RTC_GUARDED_BY(rtcp_receiver_lock_);
ReportBlockMap received_report_blocks_ RTC_GUARDED_BY(rtcp_receiver_lock_);
std::map<uint32_t, LastFirStatus> last_fir_
std::unordered_map<uint32_t, LastFirStatus> last_fir_
RTC_GUARDED_BY(rtcp_receiver_lock_);
// The last time we received an RTCP Report block for this module.