perf: prune unused interned strings (#8653) (#8659)

This commit is contained in:
Charles Kerr
2026-03-08 12:21:27 -05:00
committed by GitHub
parent db9a0cc6ec
commit 9a44fce49d
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(
std::unique_ptr<Prefs> prefs,
bool minimized,
@@ -202,6 +213,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

@@ -52,10 +52,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
{
@@ -92,6 +89,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;
@@ -115,6 +113,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_;