perf: prune unused interned strings (#8653)

This commit is contained in:
Charles Kerr
2026-03-05 10:08:26 -06:00
committed by GitHub
parent eac99ff1a0
commit 105224de1d
2 changed files with 20 additions and 4 deletions

View File

@@ -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)

View File

@@ -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_;