From b47ac4bbcf91ae2cd4fc79e9ff9b2fc78d727d5b Mon Sep 17 00:00:00 2001 From: David Schulz Date: Tue, 22 Oct 2024 15:30:53 +0200 Subject: [PATCH] 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 --- src/plugins/texteditor/texteditorplugin.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/plugins/texteditor/texteditorplugin.cpp b/src/plugins/texteditor/texteditorplugin.cpp index d423c75e4d8..c530524a38a 100644 --- a/src/plugins/texteditor/texteditorplugin.cpp +++ b/src/plugins/texteditor/texteditorplugin.cpp @@ -48,6 +48,7 @@ #include #include +#include #include #include #include @@ -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()