Mimetype optimization
Jakub Stachowski
qbast at go2.pl
Tue Apr 22 20:06:57 CEST 2008
Hello,
profiling dolphin while opening /usr/bin shows that about 35% of time is spent
in QRegExp matching called by kmimefactory.cpp: matchFileName. This function
already contains optimizations: for some simple (but popular) patterns like
*.something or something* it uses direct comparision instead of QRegExp big
gun. It looks like:
if (pattern like *.something && filename long enough to match the pattern)
compare directly;.
However for short names (lots of them in /usr/bin) it often falls back to slow
path. Attached patch changes is to:
if (pattern like *.something) {
if (filename not long enough to match) return false;
else compare directly;
}
and detects patterns without wildcards (is checking for *,? and ] enough?)
Results (measured by callgrind):
Unpatched, for 179 calls to KMimeTypeFactory::findFromFileName
- 5554 calls to QRegExp::exactMatch, which accounts for 35% of CPU time
Patched, for 150 calls to KMimeTypeFactory::findFromFileName
- QRegExp matched 13 times. findFromFileName takes 0.67% of CPU time
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mimefactory.patch
Type: text/x-diff
Size: 1530 bytes
Desc: not available
Url : http://mail.kde.org/pipermail/kde-optimize/attachments/20080422/28a45587/attachment.bin
More information about the Kde-optimize
mailing list