perf(frontend):使用tcmalloc优化内存占用与内存与内存碎片问题

This commit is contained in:
iaom 2023-09-19 15:40:13 +08:00
parent edd051de40
commit b70562c76c
10 changed files with 62 additions and 48 deletions

View File

@ -91,6 +91,7 @@ target_link_libraries(ukui-search PRIVATE
chinese-segmentation chinese-segmentation
kysdk-waylandhelper kysdk-waylandhelper
qtsingleapplication qtsingleapplication
tcmalloc_minimal
) )
target_include_directories(ukui-search PRIVATE target_include_directories(ukui-search PRIVATE

View File

@ -32,6 +32,7 @@
#include <KWindowEffects> #include <KWindowEffects>
#include <KWindowSystem> #include <KWindowSystem>
#include <QtX11Extras/QX11Info> #include <QtX11Extras/QX11Info>
#include <gperftools/malloc_extension.h>
#include "ukuistylehelper/ukuistylehelper.h" #include "ukuistylehelper/ukuistylehelper.h"
#include "windowmanager/windowmanager.h" #include "windowmanager/windowmanager.h"
#include "global-settings.h" #include "global-settings.h"
@ -374,6 +375,15 @@ bool MainWindow::tryHideMainwindow()
Q_EMIT m_searchResultPage->stopSearch(); Q_EMIT m_searchResultPage->stopSearch();
this->clearSearchResult(); this->clearSearchResult();
this->hide(); this->hide();
if(!m_releaseFreeMemoryTimerWorking) {
m_releaseFreeMemoryTimerWorking = true;
QTimer::singleShot(2000, this, [&](){
if(!this->isVisible()) {
MallocExtension::instance()->ReleaseFreeMemory();
}
m_releaseFreeMemoryTimerWorking = false;
});
}
return true; return true;
} else { } else {
//有上层弹窗未关闭,不允许隐藏主界面 //有上层弹窗未关闭,不允许隐藏主界面

View File

@ -115,6 +115,7 @@ private:
QSettings *m_settings = nullptr; QSettings *m_settings = nullptr;
AppWidgetPlugin *m_appWidgetPlugin = nullptr; AppWidgetPlugin *m_appWidgetPlugin = nullptr;
bool m_isIndexSearch = false; bool m_isIndexSearch = false;
bool m_releaseFreeMemoryTimerWorking = false;
}; };
} }

View File

@ -22,6 +22,7 @@
#include <QTranslator> #include <QTranslator>
#include <QLocale> #include <QLocale>
#include <QApplication> #include <QApplication>
#include <gperftools/malloc_extension.h>
#include <QCommandLineParser> #include <QCommandLineParser>
#include "plugin-manager.h" #include "plugin-manager.h"
#include "icon-loader.h" #include "icon-loader.h"
@ -71,6 +72,7 @@ UkuiSearchGui::UkuiSearchGui(int &argc,
} }
qDebug() << "Loading plugins and resources..."; qDebug() << "Loading plugins and resources...";
MallocExtension::Initialize();
SearchPluginManager::getInstance(); SearchPluginManager::getInstance();
PluginManager::getInstance(); PluginManager::getInstance();

View File

@ -50,12 +50,12 @@
<context> <context>
<name>UkuiSearch::MainWindow</name> <name>UkuiSearch::MainWindow</name>
<message> <message>
<location filename="../../../frontend/mainwindow.cpp" line="72"/> <location filename="../../../frontend/mainwindow.cpp" line="73"/>
<source>ukui-search</source> <source>ukui-search</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../../frontend/mainwindow.cpp" line="80"/> <location filename="../../../frontend/mainwindow.cpp" line="81"/>
<source>Global Search</source> <source>Global Search</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
@ -71,32 +71,32 @@
<context> <context>
<name>UkuiSearch::UkuiSearchGui</name> <name>UkuiSearch::UkuiSearchGui</name>
<message> <message>
<location filename="../../../frontend/ukui-search-gui.cpp" line="109"/> <location filename="../../../frontend/ukui-search-gui.cpp" line="111"/>
<source>Quit ukui-search application</source> <source>Quit ukui-search application</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../../frontend/ukui-search-gui.cpp" line="112"/> <location filename="../../../frontend/ukui-search-gui.cpp" line="114"/>
<source>Show main window</source> <source>Show main window</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../../frontend/ukui-search-gui.cpp" line="115"/> <location filename="../../../frontend/ukui-search-gui.cpp" line="117"/>
<source>unregister a plugin with &lt;pluginName&gt;</source> <source>unregister a plugin with &lt;pluginName&gt;</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../../frontend/ukui-search-gui.cpp" line="118"/> <location filename="../../../frontend/ukui-search-gui.cpp" line="120"/>
<source>register a plugin with &lt;pluginName&gt;</source> <source>register a plugin with &lt;pluginName&gt;</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../../frontend/ukui-search-gui.cpp" line="121"/> <location filename="../../../frontend/ukui-search-gui.cpp" line="123"/>
<source>move &lt;pluginName&gt; to the target pos</source> <source>move &lt;pluginName&gt; to the target pos</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../../frontend/ukui-search-gui.cpp" line="124"/> <location filename="../../../frontend/ukui-search-gui.cpp" line="126"/>
<source>move plugin to &lt;index&gt;</source> <source>move plugin to &lt;index&gt;</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>

View File

@ -50,12 +50,12 @@
<context> <context>
<name>UkuiSearch::MainWindow</name> <name>UkuiSearch::MainWindow</name>
<message> <message>
<location filename="../../../frontend/mainwindow.cpp" line="72"/> <location filename="../../../frontend/mainwindow.cpp" line="73"/>
<source>ukui-search</source> <source>ukui-search</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../../frontend/mainwindow.cpp" line="80"/> <location filename="../../../frontend/mainwindow.cpp" line="81"/>
<source>Global Search</source> <source>Global Search</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
@ -71,32 +71,32 @@
<context> <context>
<name>UkuiSearch::UkuiSearchGui</name> <name>UkuiSearch::UkuiSearchGui</name>
<message> <message>
<location filename="../../../frontend/ukui-search-gui.cpp" line="109"/> <location filename="../../../frontend/ukui-search-gui.cpp" line="111"/>
<source>Quit ukui-search application</source> <source>Quit ukui-search application</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../../frontend/ukui-search-gui.cpp" line="112"/> <location filename="../../../frontend/ukui-search-gui.cpp" line="114"/>
<source>Show main window</source> <source>Show main window</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../../frontend/ukui-search-gui.cpp" line="115"/> <location filename="../../../frontend/ukui-search-gui.cpp" line="117"/>
<source>unregister a plugin with &lt;pluginName&gt;</source> <source>unregister a plugin with &lt;pluginName&gt;</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../../frontend/ukui-search-gui.cpp" line="118"/> <location filename="../../../frontend/ukui-search-gui.cpp" line="120"/>
<source>register a plugin with &lt;pluginName&gt;</source> <source>register a plugin with &lt;pluginName&gt;</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../../frontend/ukui-search-gui.cpp" line="121"/> <location filename="../../../frontend/ukui-search-gui.cpp" line="123"/>
<source>move &lt;pluginName&gt; to the target pos</source> <source>move &lt;pluginName&gt; to the target pos</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../../frontend/ukui-search-gui.cpp" line="124"/> <location filename="../../../frontend/ukui-search-gui.cpp" line="126"/>
<source>move plugin to &lt;index&gt;</source> <source>move plugin to &lt;index&gt;</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>

View File

@ -57,12 +57,12 @@
<context> <context>
<name>UkuiSearch::MainWindow</name> <name>UkuiSearch::MainWindow</name>
<message> <message>
<location filename="../../frontend/mainwindow.cpp" line="72"/> <location filename="../../frontend/mainwindow.cpp" line="73"/>
<source>ukui-search</source> <source>ukui-search</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../../frontend/mainwindow.cpp" line="80"/> <location filename="../../frontend/mainwindow.cpp" line="81"/>
<source>Global Search</source> <source>Global Search</source>
<translation></translation> <translation></translation>
</message> </message>
@ -205,32 +205,32 @@
<context> <context>
<name>UkuiSearch::UkuiSearchGui</name> <name>UkuiSearch::UkuiSearchGui</name>
<message> <message>
<location filename="../../frontend/ukui-search-gui.cpp" line="109"/> <location filename="../../frontend/ukui-search-gui.cpp" line="111"/>
<source>Quit ukui-search application</source> <source>Quit ukui-search application</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../../frontend/ukui-search-gui.cpp" line="112"/> <location filename="../../frontend/ukui-search-gui.cpp" line="114"/>
<source>Show main window</source> <source>Show main window</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../../frontend/ukui-search-gui.cpp" line="115"/> <location filename="../../frontend/ukui-search-gui.cpp" line="117"/>
<source>unregister a plugin with &lt;pluginName&gt;</source> <source>unregister a plugin with &lt;pluginName&gt;</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../frontend/ukui-search-gui.cpp" line="118"/> <location filename="../../frontend/ukui-search-gui.cpp" line="120"/>
<source>register a plugin with &lt;pluginName&gt;</source> <source>register a plugin with &lt;pluginName&gt;</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../frontend/ukui-search-gui.cpp" line="121"/> <location filename="../../frontend/ukui-search-gui.cpp" line="123"/>
<source>move &lt;pluginName&gt; to the target pos</source> <source>move &lt;pluginName&gt; to the target pos</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../frontend/ukui-search-gui.cpp" line="124"/> <location filename="../../frontend/ukui-search-gui.cpp" line="126"/>
<source>move plugin to &lt;index&gt;</source> <source>move plugin to &lt;index&gt;</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>

View File

@ -57,12 +57,12 @@
<context> <context>
<name>UkuiSearch::MainWindow</name> <name>UkuiSearch::MainWindow</name>
<message> <message>
<location filename="../../frontend/mainwindow.cpp" line="72"/> <location filename="../../frontend/mainwindow.cpp" line="73"/>
<source>ukui-search</source> <source>ukui-search</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../../frontend/mainwindow.cpp" line="80"/> <location filename="../../frontend/mainwindow.cpp" line="81"/>
<source>Global Search</source> <source>Global Search</source>
<translation></translation> <translation></translation>
</message> </message>
@ -205,32 +205,32 @@
<context> <context>
<name>UkuiSearch::UkuiSearchGui</name> <name>UkuiSearch::UkuiSearchGui</name>
<message> <message>
<location filename="../../frontend/ukui-search-gui.cpp" line="109"/> <location filename="../../frontend/ukui-search-gui.cpp" line="111"/>
<source>Quit ukui-search application</source> <source>Quit ukui-search application</source>
<translation> </translation> <translation> </translation>
</message> </message>
<message> <message>
<location filename="../../frontend/ukui-search-gui.cpp" line="112"/> <location filename="../../frontend/ukui-search-gui.cpp" line="114"/>
<source>Show main window</source> <source>Show main window</source>
<translation> </translation> <translation> </translation>
</message> </message>
<message> <message>
<location filename="../../frontend/ukui-search-gui.cpp" line="115"/> <location filename="../../frontend/ukui-search-gui.cpp" line="117"/>
<source>unregister a plugin with &lt;pluginName&gt;</source> <source>unregister a plugin with &lt;pluginName&gt;</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../frontend/ukui-search-gui.cpp" line="118"/> <location filename="../../frontend/ukui-search-gui.cpp" line="120"/>
<source>register a plugin with &lt;pluginName&gt;</source> <source>register a plugin with &lt;pluginName&gt;</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../frontend/ukui-search-gui.cpp" line="121"/> <location filename="../../frontend/ukui-search-gui.cpp" line="123"/>
<source>move &lt;pluginName&gt; to the target pos</source> <source>move &lt;pluginName&gt; to the target pos</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../frontend/ukui-search-gui.cpp" line="124"/> <location filename="../../frontend/ukui-search-gui.cpp" line="126"/>
<source>move plugin to &lt;index&gt;</source> <source>move plugin to &lt;index&gt;</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>

View File

@ -357,12 +357,12 @@
<context> <context>
<name>UkuiSearch::MainWindow</name> <name>UkuiSearch::MainWindow</name>
<message> <message>
<location filename="../../frontend/mainwindow.cpp" line="72"/> <location filename="../../frontend/mainwindow.cpp" line="73"/>
<source>ukui-search</source> <source>ukui-search</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../frontend/mainwindow.cpp" line="80"/> <location filename="../../frontend/mainwindow.cpp" line="81"/>
<source>Global Search</source> <source>Global Search</source>
<translation type="unfinished">Genel Arama</translation> <translation type="unfinished">Genel Arama</translation>
</message> </message>
@ -541,32 +541,32 @@
<context> <context>
<name>UkuiSearch::UkuiSearchGui</name> <name>UkuiSearch::UkuiSearchGui</name>
<message> <message>
<location filename="../../frontend/ukui-search-gui.cpp" line="109"/> <location filename="../../frontend/ukui-search-gui.cpp" line="111"/>
<source>Quit ukui-search application</source> <source>Quit ukui-search application</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../frontend/ukui-search-gui.cpp" line="112"/> <location filename="../../frontend/ukui-search-gui.cpp" line="114"/>
<source>Show main window</source> <source>Show main window</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../frontend/ukui-search-gui.cpp" line="115"/> <location filename="../../frontend/ukui-search-gui.cpp" line="117"/>
<source>unregister a plugin with &lt;pluginName&gt;</source> <source>unregister a plugin with &lt;pluginName&gt;</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../frontend/ukui-search-gui.cpp" line="118"/> <location filename="../../frontend/ukui-search-gui.cpp" line="120"/>
<source>register a plugin with &lt;pluginName&gt;</source> <source>register a plugin with &lt;pluginName&gt;</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../frontend/ukui-search-gui.cpp" line="121"/> <location filename="../../frontend/ukui-search-gui.cpp" line="123"/>
<source>move &lt;pluginName&gt; to the target pos</source> <source>move &lt;pluginName&gt; to the target pos</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../frontend/ukui-search-gui.cpp" line="124"/> <location filename="../../frontend/ukui-search-gui.cpp" line="126"/>
<source>move plugin to &lt;index&gt;</source> <source>move plugin to &lt;index&gt;</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>

View File

@ -119,12 +119,12 @@
<context> <context>
<name>UkuiSearch::MainWindow</name> <name>UkuiSearch::MainWindow</name>
<message> <message>
<location filename="../../frontend/mainwindow.cpp" line="72"/> <location filename="../../frontend/mainwindow.cpp" line="73"/>
<source>ukui-search</source> <source>ukui-search</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../../frontend/mainwindow.cpp" line="80"/> <location filename="../../frontend/mainwindow.cpp" line="81"/>
<source>Global Search</source> <source>Global Search</source>
<translation></translation> <translation></translation>
</message> </message>
@ -351,32 +351,32 @@
<context> <context>
<name>UkuiSearch::UkuiSearchGui</name> <name>UkuiSearch::UkuiSearchGui</name>
<message> <message>
<location filename="../../frontend/ukui-search-gui.cpp" line="109"/> <location filename="../../frontend/ukui-search-gui.cpp" line="111"/>
<source>Quit ukui-search application</source> <source>Quit ukui-search application</source>
<translation>退</translation> <translation>退</translation>
</message> </message>
<message> <message>
<location filename="../../frontend/ukui-search-gui.cpp" line="112"/> <location filename="../../frontend/ukui-search-gui.cpp" line="114"/>
<source>Show main window</source> <source>Show main window</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../../frontend/ukui-search-gui.cpp" line="115"/> <location filename="../../frontend/ukui-search-gui.cpp" line="117"/>
<source>unregister a plugin with &lt;pluginName&gt;</source> <source>unregister a plugin with &lt;pluginName&gt;</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../frontend/ukui-search-gui.cpp" line="118"/> <location filename="../../frontend/ukui-search-gui.cpp" line="120"/>
<source>register a plugin with &lt;pluginName&gt;</source> <source>register a plugin with &lt;pluginName&gt;</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../frontend/ukui-search-gui.cpp" line="121"/> <location filename="../../frontend/ukui-search-gui.cpp" line="123"/>
<source>move &lt;pluginName&gt; to the target pos</source> <source>move &lt;pluginName&gt; to the target pos</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../frontend/ukui-search-gui.cpp" line="124"/> <location filename="../../frontend/ukui-search-gui.cpp" line="126"/>
<source>move plugin to &lt;index&gt;</source> <source>move plugin to &lt;index&gt;</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>