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.
This commit is contained in:
futpib
2026-02-18 14:44:39 +00:00
committed by John Preston
parent 1a35929eb8
commit ec7c76b8d2
5 changed files with 32 additions and 17 deletions

View File

@@ -491,6 +491,7 @@ PRIVATE
chat_helpers/ttl_media_layer_widget.h
core/application.cpp
core/application.h
core/cached_webview_availability.h
core/bank_card_click_handler.cpp
core/bank_card_click_handler.h
core/base_integration.cpp

View File

@@ -88,7 +88,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/premium_limits_box.h"
#include "ui/accessible/ui_accessible_factory.h"
#include "ui/boxes/confirm_box.h"
#include "ui/controls/location_picker.h"
#include "core/cached_webview_availability.h"
#include "styles/style_window.h"
#include <QtCore/QStandardPaths>
@@ -326,9 +326,8 @@ void Application::run() {
QMimeDatabase().mimeTypeForName(u"text/plain"_q);
// Check now to avoid re-entrance later.
[[maybe_unused]] const auto ivSupported = Iv::ShowButton();
[[maybe_unused]] const auto lpAvailable = Ui::LocationPicker::Available(
{});
[[maybe_unused]] const auto &webviewAvailability
= Core::CachedWebviewAvailability();
_windows.emplace(nullptr, std::make_unique<Window::Controller>());
setLastActiveWindow(_windows.front().second.get());

View File

@@ -0,0 +1,19 @@
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "webview/webview_interface.h"
namespace Core {
[[nodiscard]] inline const Webview::Available &CachedWebviewAvailability() {
static const auto result = Webview::Availability();
return result;
}
} // namespace Core

View File

@@ -8,7 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "iv/iv_data.h"
#include "iv/iv_prepare.h"
#include "webview/webview_interface.h"
#include "core/cached_webview_availability.h"
#include <QtCore/QRegularExpression>
#include <QtCore/QUrl>
@@ -102,12 +102,9 @@ QString SiteNameFromUrl(const QString &url) {
}
bool ShowButton() {
static const auto Supported = [&] {
const auto availability = Webview::Availability();
return availability.customSchemeRequests
&& availability.customRangeRequests;
}();
return Supported;
const auto &availability = Core::CachedWebviewAvailability();
return availability.customSchemeRequests
&& availability.customRangeRequests;
}
void RecordShowFailure() {

View File

@@ -38,6 +38,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "webview/webview_data_stream_memory.h"
#include "webview/webview_embed.h"
#include "webview/webview_interface.h"
#include "core/cached_webview_availability.h"
#include "window/themes/window_theme.h"
#include "styles/style_chat_helpers.h"
#include "styles/style_dialogs.h"
@@ -772,12 +773,10 @@ std::shared_ptr<Main::SessionShow> LocationPicker::uiShow() {
}
bool LocationPicker::Available(const LocationPickerConfig &config) {
static const auto Supported = [&] {
const auto availability = Webview::Availability();
return availability.customSchemeRequests
&& availability.customReferer;
}();
return Supported && !config.mapsToken.isEmpty();
const auto &availability = Core::CachedWebviewAvailability();
return availability.customSchemeRequests
&& availability.customReferer
&& !config.mapsToken.isEmpty();
}
void LocationPicker::setup(const Descriptor &descriptor) {