[PATCH] KFileItem performance improvement

Peter Penz peter.penz at gmx.at
Thu Jun 26 19:56:28 BST 2008


When opening a directory with several hundreds or thousands of items and 
turning on previews in Dolphin/Konqueror, the layout of items can get quite 
slow when using the icon view.

Each time an icon gets exchanged by the preview image, a KDirModel::setData() 
is invoked which sends the signal 'dataChanged()'. This signal is received by 
QListView. Now QListView asks the KFileItemDelegate for the sizeHint() of 
each (!) item to do a relayout [1].

KFileItemDelegate::sizeHint() is not trivial, as it is tries to keep a minimal 
width for the item. 50 % of the performance is spend in 
KFileItemDelegate::initStyleOption, there 82 % are spend for getting the icon 
from the model. From there 85 % are spend for getting the icon name of 
KFileItem (the expensive part there is the MIME type block). This means in 
summary 35 % of the runtime in KFileItemDelegate::sizeHint() is spend in 

I checked how often KFileItem::iconName() is invoked on the same instance of 
KFileItem when showing a directory with 800 items and turning on previews. 
Result: in average KFileItem::iconName() is invoked around 300 times in 
average for each (!) KFileItem instance.

Attached is a patch which remembers the icon name after KFileItem::iconName() 
is invoked at least once.

Is it OK to commit this patch?


[1] we could bypass this issue a little bit by turning on the uniformItemSizes 
property of QListView and by changing the previews block by block, but a 
relayout without uniformItemSizes must be done afterwards. This relayout can 
still take up to 1 second when having a directory with 10000 items (runtime 
complexity O(n*n)) on a 2,1 GHz CPU...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kfileitem.patch
Type: text/x-diff
Size: 1824 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20080626/b441fdad/attachment.patch>

More information about the kde-core-devel mailing list