Use faster containers for bulk-populated custom emoji maps

Replace base::flat_map (sorted vector with O(n) insertion) with
std::unordered_map for CustomEmojiManager::_instances and std::map
for EmojiListWidget::_customEmoji. These maps accumulate ~8000
entries during startup with unsorted keys, causing O(n²) total
insertion cost. This change reduces refreshCustom() from ~3s to
~50ms (57x speedup).
This commit is contained in:
futpib
2026-02-18 00:00:04 +00:00
committed by John Preston
parent f9bf1e9372
commit dc6b9dda4d
2 changed files with 4 additions and 2 deletions
@@ -13,6 +13,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/round_rect.h" #include "ui/round_rect.h"
#include "base/timer.h" #include "base/timer.h"
#include <map>
class StickerPremiumMark; class StickerPremiumMark;
namespace style { namespace style {
@@ -438,7 +440,7 @@ private:
QVector<EmojiPtr> _emoji[kEmojiSectionCount]; QVector<EmojiPtr> _emoji[kEmojiSectionCount];
std::vector<CustomSet> _custom; std::vector<CustomSet> _custom;
base::flat_set<DocumentId> _restrictedCustomList; base::flat_set<DocumentId> _restrictedCustomList;
base::flat_map<EmojiStatusId, CustomEmojiInstance> _customEmoji; std::map<EmojiStatusId, CustomEmojiInstance> _customEmoji;
base::flat_map< base::flat_map<
DocumentId, DocumentId,
std::unique_ptr<Ui::Text::CustomEmoji>> _customRecent; std::unique_ptr<Ui::Text::CustomEmoji>> _customRecent;
@@ -149,7 +149,7 @@ private:
const not_null<Session*> _owner; const not_null<Session*> _owner;
std::array< std::array<
base::flat_map< std::unordered_map<
DocumentId, DocumentId,
std::unique_ptr<Ui::CustomEmoji::Instance>>, std::unique_ptr<Ui::CustomEmoji::Instance>>,
kSizeCount> _instances; kSizeCount> _instances;