From dc6b9dda4d9398d231eea276cb0af9136c873b3a Mon Sep 17 00:00:00 2001 From: futpib Date: Wed, 18 Feb 2026 00:00:04 +0000 Subject: [PATCH] Use faster containers for bulk-populated custom emoji maps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). --- Telegram/SourceFiles/chat_helpers/emoji_list_widget.h | 4 +++- Telegram/SourceFiles/data/stickers/data_custom_emoji.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.h b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.h index 6402935140..59f623a8c3 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.h @@ -13,6 +13,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/round_rect.h" #include "base/timer.h" +#include + class StickerPremiumMark; namespace style { @@ -438,7 +440,7 @@ private: QVector _emoji[kEmojiSectionCount]; std::vector _custom; base::flat_set _restrictedCustomList; - base::flat_map _customEmoji; + std::map _customEmoji; base::flat_map< DocumentId, std::unique_ptr> _customRecent; diff --git a/Telegram/SourceFiles/data/stickers/data_custom_emoji.h b/Telegram/SourceFiles/data/stickers/data_custom_emoji.h index c35d7520fb..1351bb0c1d 100644 --- a/Telegram/SourceFiles/data/stickers/data_custom_emoji.h +++ b/Telegram/SourceFiles/data/stickers/data_custom_emoji.h @@ -149,7 +149,7 @@ private: const not_null _owner; std::array< - base::flat_map< + std::unordered_map< DocumentId, std::unique_ptr>, kSizeCount> _instances;