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
kysdk-waylandhelper
qtsingleapplication
tcmalloc_minimal
)
target_include_directories(ukui-search PRIVATE

View File

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

View File

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

View File

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

View File

@ -50,12 +50,12 @@
<context>
<name>UkuiSearch::MainWindow</name>
<message>
<location filename="../../../frontend/mainwindow.cpp" line="72"/>
<location filename="../../../frontend/mainwindow.cpp" line="73"/>
<source>ukui-search</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../frontend/mainwindow.cpp" line="80"/>
<location filename="../../../frontend/mainwindow.cpp" line="81"/>
<source>Global Search</source>
<translation type="unfinished"></translation>
</message>
@ -71,32 +71,32 @@
<context>
<name>UkuiSearch::UkuiSearchGui</name>
<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>
<translation type="unfinished"></translation>
</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>
<translation type="unfinished"></translation>
</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>
<translation type="unfinished"></translation>
</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>
<translation type="unfinished"></translation>
</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>
<translation type="unfinished"></translation>
</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>
<translation type="unfinished"></translation>
</message>

View File

@ -50,12 +50,12 @@
<context>
<name>UkuiSearch::MainWindow</name>
<message>
<location filename="../../../frontend/mainwindow.cpp" line="72"/>
<location filename="../../../frontend/mainwindow.cpp" line="73"/>
<source>ukui-search</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../frontend/mainwindow.cpp" line="80"/>
<location filename="../../../frontend/mainwindow.cpp" line="81"/>
<source>Global Search</source>
<translation type="unfinished"></translation>
</message>
@ -71,32 +71,32 @@
<context>
<name>UkuiSearch::UkuiSearchGui</name>
<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>
<translation type="unfinished"></translation>
</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>
<translation type="unfinished"></translation>
</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>
<translation type="unfinished"></translation>
</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>
<translation type="unfinished"></translation>
</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>
<translation type="unfinished"></translation>
</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>
<translation type="unfinished"></translation>
</message>

View File

@ -57,12 +57,12 @@
<context>
<name>UkuiSearch::MainWindow</name>
<message>
<location filename="../../frontend/mainwindow.cpp" line="72"/>
<location filename="../../frontend/mainwindow.cpp" line="73"/>
<source>ukui-search</source>
<translation></translation>
</message>
<message>
<location filename="../../frontend/mainwindow.cpp" line="80"/>
<location filename="../../frontend/mainwindow.cpp" line="81"/>
<source>Global Search</source>
<translation></translation>
</message>
@ -205,32 +205,32 @@
<context>
<name>UkuiSearch::UkuiSearchGui</name>
<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>
<translation></translation>
</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>
<translation></translation>
</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>
<translation type="unfinished"></translation>
</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>
<translation type="unfinished"></translation>
</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>
<translation type="unfinished"></translation>
</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>
<translation type="unfinished"></translation>
</message>

View File

@ -57,12 +57,12 @@
<context>
<name>UkuiSearch::MainWindow</name>
<message>
<location filename="../../frontend/mainwindow.cpp" line="72"/>
<location filename="../../frontend/mainwindow.cpp" line="73"/>
<source>ukui-search</source>
<translation></translation>
</message>
<message>
<location filename="../../frontend/mainwindow.cpp" line="80"/>
<location filename="../../frontend/mainwindow.cpp" line="81"/>
<source>Global Search</source>
<translation></translation>
</message>
@ -205,32 +205,32 @@
<context>
<name>UkuiSearch::UkuiSearchGui</name>
<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>
<translation> </translation>
</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>
<translation> </translation>
</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>
<translation type="unfinished"></translation>
</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>
<translation type="unfinished"></translation>
</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>
<translation type="unfinished"></translation>
</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>
<translation type="unfinished"></translation>
</message>

View File

@ -357,12 +357,12 @@
<context>
<name>UkuiSearch::MainWindow</name>
<message>
<location filename="../../frontend/mainwindow.cpp" line="72"/>
<location filename="../../frontend/mainwindow.cpp" line="73"/>
<source>ukui-search</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../frontend/mainwindow.cpp" line="80"/>
<location filename="../../frontend/mainwindow.cpp" line="81"/>
<source>Global Search</source>
<translation type="unfinished">Genel Arama</translation>
</message>
@ -541,32 +541,32 @@
<context>
<name>UkuiSearch::UkuiSearchGui</name>
<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>
<translation type="unfinished"></translation>
</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>
<translation type="unfinished"></translation>
</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>
<translation type="unfinished"></translation>
</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>
<translation type="unfinished"></translation>
</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>
<translation type="unfinished"></translation>
</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>
<translation type="unfinished"></translation>
</message>

View File

@ -119,12 +119,12 @@
<context>
<name>UkuiSearch::MainWindow</name>
<message>
<location filename="../../frontend/mainwindow.cpp" line="72"/>
<location filename="../../frontend/mainwindow.cpp" line="73"/>
<source>ukui-search</source>
<translation></translation>
</message>
<message>
<location filename="../../frontend/mainwindow.cpp" line="80"/>
<location filename="../../frontend/mainwindow.cpp" line="81"/>
<source>Global Search</source>
<translation></translation>
</message>
@ -351,32 +351,32 @@
<context>
<name>UkuiSearch::UkuiSearchGui</name>
<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>
<translation>退</translation>
</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>
<translation></translation>
</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>
<translation type="unfinished"></translation>
</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>
<translation type="unfinished"></translation>
</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>
<translation type="unfinished"></translation>
</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>
<translation type="unfinished"></translation>
</message>