Use unordered map in RoundRobinPacketQueue

In highly loaded Media Servers, RoundRobinPacketQueue's usage of
std::map attributes to around 0.3% CPU. In profiling, it has been found
that it's the `streams_` map that is the culprit and std::map::find
being the function that is used most.

By using an unordered map, lookups should be faster. This will be
evaluated and if this commit doesn't show results, it will be reverted.

Bug: webrtc:12689
Change-Id: Ia368f1184130298cfbb9064528828435aa7a5c66
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/216320
Reviewed-by: Erik Språng <sprang@webrtc.org>
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33848}
This commit is contained in:
Victor Boivie 2021-04-27 10:13:46 +02:00 committed by Commit Bot
parent a63bee55f2
commit 723873b841

View File

@ -19,6 +19,7 @@
#include <memory>
#include <queue>
#include <set>
#include <unordered_map>
#include "absl/types/optional.h"
#include "api/transport/webrtc_key_value_config.h"
@ -163,7 +164,7 @@ class RoundRobinPacketQueue {
std::multimap<StreamPrioKey, uint32_t> stream_priorities_;
// A map of SSRCs to Streams.
std::map<uint32_t, Stream> streams_;
std::unordered_map<uint32_t, Stream> streams_;
// The enqueue time of every packet currently in the queue. Used to figure out
// the age of the oldest packet in the queue.