Test custom emoji timer-by-on_main optimization.

This commit is contained in:
John Preston 2022-10-06 17:05:50 +04:00
parent bacc30e296
commit 3aa7f4dd62
2 changed files with 45 additions and 4 deletions

View File

@ -33,6 +33,9 @@ namespace Data {
namespace { namespace {
constexpr auto kMaxPerRequest = 100; constexpr auto kMaxPerRequest = 100;
#if 0 // inject-to-on_main
constexpr auto kUnsubscribeUpdatesDelay = 3 * crl::time(1000);
#endif
using SizeTag = CustomEmojiManager::SizeTag; using SizeTag = CustomEmojiManager::SizeTag;
@ -730,15 +733,40 @@ void CustomEmojiManager::repaintLater(
} }
} }
bunch.when = request.when; bunch.when = request.when;
#if 0 // inject-to-on_main
_repaintsLastAdded = request.when;
#endif
} }
bunch.instances.emplace_back(instance); bunch.instances.emplace_back(instance);
scheduleRepaintTimer(); scheduleRepaintTimer();
} }
bool CustomEmojiManager::checkEmptyRepaints() {
if (!_repaints.empty()) {
return false;
#if 0 // inject-to-on_main
} else if (_repaintsLifetime
&& crl::now() >= _repaintsLastAdded + kUnsubscribeUpdatesDelay) {
_repaintsLifetime.destroy();
#endif
}
return true;
}
void CustomEmojiManager::scheduleRepaintTimer() { void CustomEmojiManager::scheduleRepaintTimer() {
if (_repaintTimerScheduled) { if (checkEmptyRepaints() || _repaintTimerScheduled) {
return; return;
} }
#if 0 // inject-to-on_main
if (!_repaintsLifetime) {
crl::on_main_update_requests(
) | rpl::start_with_next([=] {
invokeRepaints();
}, _repaintsLifetime);
}
#endif
_repaintTimerScheduled = true; _repaintTimerScheduled = true;
Ui::PostponeCall(this, [=] { Ui::PostponeCall(this, [=] {
_repaintTimerScheduled = false; _repaintTimerScheduled = false;
@ -765,6 +793,9 @@ void CustomEmojiManager::scheduleRepaintTimer() {
void CustomEmojiManager::invokeRepaints() { void CustomEmojiManager::invokeRepaints() {
_repaintNext = 0; _repaintNext = 0;
if (checkEmptyRepaints()) {
return;
}
const auto now = crl::now(); const auto now = crl::now();
auto repaint = std::vector<base::weak_ptr<Ui::CustomEmoji::Instance>>(); auto repaint = std::vector<base::weak_ptr<Ui::CustomEmoji::Instance>>();
for (auto i = begin(_repaints); i != end(_repaints);) { for (auto i = begin(_repaints); i != end(_repaints);) {
@ -783,10 +814,14 @@ void CustomEmojiManager::invokeRepaints() {
} }
i = _repaints.erase(i); i = _repaints.erase(i);
} }
for (const auto &weak : repaint) { if (!repaint.empty()) {
if (const auto strong = weak.get()) { for (const auto &weak : repaint) {
strong->repaint(); if (const auto strong = weak.get()) {
strong->repaint();
}
} }
} else if (_repaintTimer.isActive()) {
return;
} }
scheduleRepaintTimer(); scheduleRepaintTimer();
} }

View File

@ -108,6 +108,7 @@ private:
not_null<Ui::CustomEmoji::Instance*> instance, not_null<Ui::CustomEmoji::Instance*> instance,
Ui::CustomEmoji::RepaintRequest request); Ui::CustomEmoji::RepaintRequest request);
void scheduleRepaintTimer(); void scheduleRepaintTimer();
bool checkEmptyRepaints();
void invokeRepaints(); void invokeRepaints();
void fillColoredFlags(not_null<DocumentData*> document); void fillColoredFlags(not_null<DocumentData*> document);
void processLoaders(not_null<DocumentData*> document); void processLoaders(not_null<DocumentData*> document);
@ -161,6 +162,11 @@ private:
bool _repaintTimerScheduled = false; bool _repaintTimerScheduled = false;
bool _requestSetsScheduled = false; bool _requestSetsScheduled = false;
#if 0 // inject-to-on_main
crl::time _repaintsLastAdded = 0;
rpl::lifetime _repaintsLifetime;
#endif
rpl::lifetime _lifetime; rpl::lifetime _lifetime;
}; };