Skip to content

Commit ec7c76b

Browse files
futpibjohn-preston
authored andcommitted
Cache Webview::Availability() result for startup checks
Iv::ShowButton() and LocationPicker::Available() each called Webview::Availability() separately (~200ms each on Linux). Replace the per-caller static caches with a single shared cache in Core::CachedWebviewAvailability(), reducing startup from two ~200ms calls to one.
1 parent 1a35929 commit ec7c76b

5 files changed

Lines changed: 32 additions & 17 deletions

File tree

Telegram/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ PRIVATE
491491
chat_helpers/ttl_media_layer_widget.h
492492
core/application.cpp
493493
core/application.h
494+
core/cached_webview_availability.h
494495
core/bank_card_click_handler.cpp
495496
core/bank_card_click_handler.h
496497
core/base_integration.cpp

Telegram/SourceFiles/core/application.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ For license and copyright information please follow this link:
8888
#include "boxes/premium_limits_box.h"
8989
#include "ui/accessible/ui_accessible_factory.h"
9090
#include "ui/boxes/confirm_box.h"
91-
#include "ui/controls/location_picker.h"
91+
#include "core/cached_webview_availability.h"
9292
#include "styles/style_window.h"
9393

9494
#include <QtCore/QStandardPaths>
@@ -326,9 +326,8 @@ void Application::run() {
326326
QMimeDatabase().mimeTypeForName(u"text/plain"_q);
327327

328328
// Check now to avoid re-entrance later.
329-
[[maybe_unused]] const auto ivSupported = Iv::ShowButton();
330-
[[maybe_unused]] const auto lpAvailable = Ui::LocationPicker::Available(
331-
{});
329+
[[maybe_unused]] const auto &webviewAvailability
330+
= Core::CachedWebviewAvailability();
332331

333332
_windows.emplace(nullptr, std::make_unique<Window::Controller>());
334333
setLastActiveWindow(_windows.front().second.get());
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
This file is part of Telegram Desktop,
3+
the official desktop application for the Telegram messaging service.
4+
5+
For license and copyright information please follow this link:
6+
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
7+
*/
8+
#pragma once
9+
10+
#include "webview/webview_interface.h"
11+
12+
namespace Core {
13+
14+
[[nodiscard]] inline const Webview::Available &CachedWebviewAvailability() {
15+
static const auto result = Webview::Availability();
16+
return result;
17+
}
18+
19+
} // namespace Core

Telegram/SourceFiles/iv/iv_data.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ For license and copyright information please follow this link:
88
#include "iv/iv_data.h"
99

1010
#include "iv/iv_prepare.h"
11-
#include "webview/webview_interface.h"
11+
#include "core/cached_webview_availability.h"
1212

1313
#include <QtCore/QRegularExpression>
1414
#include <QtCore/QUrl>
@@ -102,12 +102,9 @@ QString SiteNameFromUrl(const QString &url) {
102102
}
103103

104104
bool ShowButton() {
105-
static const auto Supported = [&] {
106-
const auto availability = Webview::Availability();
107-
return availability.customSchemeRequests
108-
&& availability.customRangeRequests;
109-
}();
110-
return Supported;
105+
const auto &availability = Core::CachedWebviewAvailability();
106+
return availability.customSchemeRequests
107+
&& availability.customRangeRequests;
111108
}
112109

113110
void RecordShowFailure() {

Telegram/SourceFiles/ui/controls/location_picker.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ For license and copyright information please follow this link:
3838
#include "webview/webview_data_stream_memory.h"
3939
#include "webview/webview_embed.h"
4040
#include "webview/webview_interface.h"
41+
#include "core/cached_webview_availability.h"
4142
#include "window/themes/window_theme.h"
4243
#include "styles/style_chat_helpers.h"
4344
#include "styles/style_dialogs.h"
@@ -772,12 +773,10 @@ std::shared_ptr<Main::SessionShow> LocationPicker::uiShow() {
772773
}
773774

774775
bool LocationPicker::Available(const LocationPickerConfig &config) {
775-
static const auto Supported = [&] {
776-
const auto availability = Webview::Availability();
777-
return availability.customSchemeRequests
778-
&& availability.customReferer;
779-
}();
780-
return Supported && !config.mapsToken.isEmpty();
776+
const auto &availability = Core::CachedWebviewAvailability();
777+
return availability.customSchemeRequests
778+
&& availability.customReferer
779+
&& !config.mapsToken.isEmpty();
781780
}
782781

783782
void LocationPicker::setup(const Descriptor &descriptor) {

0 commit comments

Comments
 (0)