From 18649971ab02d2f3fc8f360aee2e3c573652b7bd Mon Sep 17 00:00:00 2001 From: Victor Boivie Date: Tue, 6 Jul 2021 22:43:47 +0200 Subject: [PATCH] Use flat_map in ReceiveStatisticsImpl std::unordered_map represents ~0.57% CPU in a loaded media server, which is expected to be reduced by using flat_map and its increased cache locality compared to std::unordered_map, which use quite a few allocations and indirections. The number of SSRCs tracked by this class is expected to be low and infrequently updated, but as GetOrCreateStatistician is called for every incoming RTP packet, lookups are frequent. Bug: webrtc:12689 Change-Id: I9a2c3798dcc7822f518e8f2624e78fceacd12d27 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/225202 Reviewed-by: Danil Chapovalov Commit-Queue: Victor Boivie Cr-Commit-Position: refs/heads/master@{#34430} --- modules/rtp_rtcp/BUILD.gn | 1 + modules/rtp_rtcp/source/receive_statistics_impl.h | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/rtp_rtcp/BUILD.gn b/modules/rtp_rtcp/BUILD.gn index f056df3651..3e25d18d84 100644 --- a/modules/rtp_rtcp/BUILD.gn +++ b/modules/rtp_rtcp/BUILD.gn @@ -303,6 +303,7 @@ rtc_library("rtp_rtcp") { "../../rtc_base/task_utils:repeating_task", "../../rtc_base/task_utils:to_queued_task", "../../rtc_base/time:timestamp_extrapolator", + "../../rtc_base/containers:flat_map", "../../system_wrappers", "../../system_wrappers:metrics", "../remote_bitrate_estimator", diff --git a/modules/rtp_rtcp/source/receive_statistics_impl.h b/modules/rtp_rtcp/source/receive_statistics_impl.h index 44f5144df9..1a70fe4ad7 100644 --- a/modules/rtp_rtcp/source/receive_statistics_impl.h +++ b/modules/rtp_rtcp/source/receive_statistics_impl.h @@ -14,7 +14,6 @@ #include #include #include -#include #include #include @@ -22,6 +21,7 @@ #include "modules/include/module_common_types_public.h" #include "modules/rtp_rtcp/include/receive_statistics.h" #include "modules/rtp_rtcp/source/rtcp_packet/report_block.h" +#include "rtc_base/containers/flat_map.h" #include "rtc_base/rate_statistics.h" #include "rtc_base/synchronization/mutex.h" #include "rtc_base/thread_annotations.h" @@ -195,8 +195,7 @@ class ReceiveStatisticsImpl : public ReceiveStatistics { size_t last_returned_ssrc_idx_; std::vector all_ssrcs_; int max_reordering_threshold_; - std::unordered_map> + flat_map> statisticians_; };