[PATCH]: KIconLoader::loadIcon() speed ups

Aaron J. Seigo aseigo at kde.org
Mon Nov 5 05:01:31 GMT 2007

hi all..

attached is a patch that rather dramatically improves the speed of 

i felt like playing with code tonight, but on something other than plasma (in 
an attempt to stave off getting burnt out dealing with QGV madnesses[1]) ... 
so when i saw a bug report from Hamish on KIconLoader performance[2] i fired 
up my text editor and got kcachegrind ready.

the main culprits were KIconLoaderPrivate::removeIconExtension which was doing 
this a little suboptimally but more importantly had a debug statement that's 
probably superfluous at this stage in devel. off it went, and that revealed 
the next horror shows.

it was using QDir::isRelativePath exactly once and that was now accounting for 
fully 33.46% of execution time. that's because it creaes a QFileInfo which 
init's a file engine ...... yeah. way too much for a hot path like loadIcon. 
i figure we don't -really- care if it's an absolute or relative path and we 
can fudge it by asking if the first character is '/'. 

i'm going to out on a limb and guess that this breaks on windows. if so, i can 
wrap it in an ifdef because the win is just way too big to ignore.

next was to preallocate enough space in the qstring used for the key to avoid 
expensive repeated reallocs, which knocked ~6% more execution speed. between 
this and the QDir removal, that was nearly 40% of execution gone.

now it's down to QPixmapCache::find() taking the most amount of time (~10%) 
mostly due to QHash it seems.

with this patch we go from ~22kis (kilo icons per second ;) to 118kis. rock 

should this go in? =)

[1] live items that accept hover events causing full screen repaints or items 
affecting the geometries of other items on the scene for no good reason

[2] http://bugs.kde.org/show_bug.cgi?id=151874

Aaron J. Seigo
humru othro a kohnu se
GPG Fingerprint: 8B8B 2209 0C6F 7C47 B1EA  EE75 D6B7 2EB1 A7F1 DB43

KDE core developer sponsored by Trolltech
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kiconloader.diff
Type: text/x-diff
Size: 3205 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20071104/12853899/attachment.diff>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20071104/12853899/attachment.sig>

More information about the kde-core-devel mailing list