TextEditor: warm up fallback font cache on windows

Loading this fallback font cache takes around 300 ms the first time an
editor is opened. Calling QFontMetrics::horizontalAdvance and passing
0x21B5 in another thread fills this cache before an editor get's opened
and removes this delay for the first editor.

Change-Id: I48c0e9b4e2466f37d064dbf854df5553b0e97ad4
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2024-10-22 15:30:53 +02:00
parent 78aa9ae0bd
commit b47ac4bbcf

View File

@@ -48,6 +48,7 @@
#include <extensionsystem/pluginmanager.h>
#include <extensionsystem/iplugin.h>
#include <utils/async.h>
#include <utils/fancylineedit.h>
#include <utils/macroexpander.h>
#include <utils/qtcassert.h>
@@ -140,6 +141,14 @@ void TextEditorPlugin::initialize()
#endif
Utils::Text::setCodeHighlighter(HighlighterHelper::highlightCode);
if (Utils::HostOsInfo::isWindowsHost()) {
// warm up the fallback font cache on windows this reduces the startup time of the first
// editor by around 300 ms
Utils::asyncRun([font = QPlainTextEdit().font()]() {
QFontMetrics(font).horizontalAdvance(QChar(0x21B5));
});
}
}
void TextEditorPlugin::extensionsInitialized()