From 105224de1df9c1ca4cdc9d789967bb40021a3c23 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 5 Mar 2026 10:08:26 -0600 Subject: [PATCH] perf: prune unused interned strings (#8653) --- qt/Application.cc | 17 +++++++++++++++++ qt/Application.h | 7 +++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/qt/Application.cc b/qt/Application.cc index e1c803c2c..bcd1b1acc 100644 --- a/qt/Application.cc +++ b/qt/Application.cc @@ -54,6 +54,7 @@ auto const FDONotificationsInterfaceName = QStringLiteral("org.freedesktop.Notif auto constexpr StatsRefreshIntervalMsec = 3000; auto constexpr SessionRefreshIntervalMsec = 3000; auto constexpr ModelRefreshIntervalMsec = 3000; +auto constexpr InternRefreshIntervalMsec = 5 * 60 * 1000; bool loadTranslation(QTranslator& translator, QString const& name, QLocale const& locale, QStringList const& search_directories) { @@ -127,6 +128,16 @@ QAccessibleInterface* accessibleFactory(QString const& className, QObject* objec } // namespace +void Application::pruneInternedStrings() +{ + std::erase_if(interned_strings_, [](QString const& str) { return str.isDetached(); }); +} + +QString Application::intern(QString const& in) +{ + return *interned_strings_.insert(in).first; +} + Application::Application( Prefs& prefs, RpcClient& rpc, @@ -203,6 +214,12 @@ Application::Application( timer->setInterval(SessionRefreshIntervalMsec); timer->start(); + timer = &intern_timer_; + connect(timer, &QTimer::timeout, this, &Application::pruneInternedStrings); + timer->setSingleShot(false); + timer->setInterval(InternRefreshIntervalMsec); + timer->start(); + maybeUpdateBlocklist(); if (!first_time) diff --git a/qt/Application.h b/qt/Application.h index df8318a3d..ca4021147 100644 --- a/qt/Application.h +++ b/qt/Application.h @@ -54,10 +54,7 @@ public: void raise() const; bool notifyApp(QString const& title, QString const& body, QStringList const& actions = {}) const; - QString const& intern(QString const& in) - { - return *interned_strings_.insert(in).first; - } + QString intern(QString const& in); [[nodiscard]] QPixmap find_favicon(QString const& sitename) const { @@ -94,6 +91,7 @@ private slots: void onTorrentsCompleted(torrent_ids_t const& torrent_ids) const; void onTorrentsEdited(torrent_ids_t const& torrent_ids) const; void onTorrentsNeedInfo(torrent_ids_t const& torrent_ids) const; + void pruneInternedStrings(); void refreshPref(int key) const; void refreshTorrents(); void saveGeometry() const; @@ -117,6 +115,7 @@ private: QTimer model_timer_; QTimer stats_timer_; QTimer session_timer_; + QTimer intern_timer_; time_t last_full_update_time_ = {}; QTranslator qt_translator_; QTranslator app_translator_;