[Development] Cut 7+ms of Qt5 startup time on Linux

Kevin Funk krf at gmx.de
Thu Oct 31 18:30:27 CET 2013

Am Donnerstag, 31. Oktober 2013, 17:52:28 schrieb Jiergir Ogoerg:
> Great, of course you're a much better/smarter programmer than me,
> but how much time of the whole parsing and loading
> (which is done line by line which is slow) does fromUtf8()
> take? If it's only like 10-20% then even if it's optimized to work 10 times
> faster in the end it's a much smaller improvement compared to
> binary loading which almost doesn't do any parsing at all, just copying
> from disk onto ready memory.


I was curious about performance bottlenecks here, too, this morning. So I had 
a quick look.

Running the attached program (main.cpp) compiled with 'g++ -g -O2 ...' through 
callgrind yielded the following results for me: 

Just showing the significant measurements:
* ~50% time (incl.) spent in xkb_keysym_from_name 
* ~21% time (incl.) spent in QString::fromUtf8_helper

So it seems there's indeed potential that optimizing QString::fromUtf8 would 
help. Not sure if there's any benefit in looking into xkb_keysym_from_name 
from xkb-common, which seems to be another bottleneck.

> If the total parsing time after your optimizations
> is still like 2x+ times slower than loading the binary cache then imo
> your optimizations should be incorporated anyway for the
> (rare) cases when there's no (binary) cache yet or when it must be updated.
> The type of code (in a loop) I mentioned which features lots of other
> decoding/operations
> besides fromUtf8():
> (snip)

While having a quick look at the code in qtablegenerator.cpp I found a minor 
performance bottleneck, patch attached.

With this patch, some iterations of the for-loop inside 
TableGenerator::parseKeySequence are saved. Given that the amount of keys 
inside the compose text file is significant smaller than 
QT_KEYSEQUENCE_MAX_LEN (== 6) in average.

Callgrind results (Instruction fetches):
* Without patch: ~34,350k
* With    patch: ~34,200k

Minor improvement, yes.

If the patch makes sense (i.e. if it is correct) I can put it on Gerrit.


Kevin Funk
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cpp
Type: text/x-c++src
Size: 445 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20131031/d7507ec5/attachment.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: loop-optimization.patch
Type: text/x-patch
Size: 1078 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20131031/d7507ec5/attachment.bin>

More information about the Development mailing list