Details
-
Bug
-
Resolution: Done
-
Not Evaluated
-
Qt Creator 4.10.2
-
None
-
CentOS 6 64-bits.
Qt 5.12.0 and QtCreator 4.10.2 being built by me using GCC 5.3.1.
Windows 10 64-bits
QtCreator 4.10.2 (official release).
-
-
e85d6b363bd039c4407bbf5367cce0efdd559945 (qt-creator/qt-creator/4.11)
Description
Someone added to our project a huge reference file stored in a C++11 string literal:
static std::string const data(R"( -1 -1 -1 -1 ... )");
The "-1 -1..." line is approximately 500000 characters long (the file actually contains multiple long lines, for a total of 3.8M characters, but a single long line is enough to reproduce the issue).
You can generate such file with the following script:
#!/bin/sh echo 'static std::string const data(R"(' yes -- "-1 " | head -n 200000 | tr -d '\n' echo echo ')");'
Opening that file is very slow: 40s on a fairly big workstation under CentOS 6, or on a standard Windows 10 laptop.
When attaching GDB, I can see that QtCreator is spending a lot of time here:
#0 0x0000003d0ba89bd4 in _wordcopy_fwd_aligned () from /lib64/libc.so.6 #1 0x0000003d0ba83a42 in memmove () from /lib64/libc.so.6 #2 0x00007f43faf36ac9 in QVector<QTextLayout::FormatRange>::erase (this=0x7fffdf565e40, abegin=0xa918d48, aend=0xa918d60) at /opt/Qt-5.12.0/include/QtCore/qvector.h:835 #3 0x00007f43faf35a6f in QVector<QTextLayout::FormatRange>::erase (this=0x7fffdf565e40, pos=0xa918d48) at /opt/Qt-5.12.0/include/QtCore/qvector.h:233 #4 0x00007f43faf32e23 in TextEditor::SyntaxHighlighterPrivate::applyFormatChanges (this=0x80501e0, from=0, charsRemoved=0, charsAdded=3843994) at../../../../src/src/plugins/texteditor/syntaxhighlighter.cpp:220 #5 0x00007f57d0fa8043 in TextEditor::SyntaxHighlighterPrivate::reformatBlock (this=0xa60d6b0, block=..., from=0, charsRemoved=0, charsAdded=3843994) at ../../../../src/src/plugins/texteditor/syntaxhighlighter.cpp:220 #6 0x00007f57d0fa7ecf in TextEditor::SyntaxHighlighterPrivate::reformatBlocks (this=0xa60d6b0, from=0, charsRemoved=0, charsAdded=3843994) at ../../../../src/src/plugins/texteditor/syntaxhighlighter.cpp:198 #7 0x00007f57d0faa2e8 in TextEditor::SyntaxHighlighterPrivate::rehighlight (this=0xa60d6b0, cursor=..., operation=QTextCursor::End) at ../../../../src/src/plugins/texteditor/syntaxhighlighter.cpp:62 #8 0x00007f57d0fa874b in TextEditor::SyntaxHighlighter::rehighlight (this=0x843fe70) at ../../../../src/src/plugins/texteditor/syntaxhighlighter.cpp:351 ...
The issue is that a quite long (181000 elements for my 3.8MB file) QVector<QTextLayout::FormatRange> is iterated on, and most of its elements are erased using QVector::erase(iterator), resulting in a lot of (quite big) memmove().