Bug 237668

Summary: Dolphin freezes while loading large directories
Product: [Applications] dolphin Reporter: Nikita Churaev <lamefun.x0r>
Component: generalAssignee: Peter Penz <peter.penz19>
Status: RESOLVED FIXED    
Severity: normal CC: faure
Priority: NOR    
Version: 16.12.2   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed In: 4.5.0
Sentry Crash Report:

Description Nikita Churaev 2010-05-14 21:32:05 UTC
Version:            (using KDE 4.4.3)
OS:                Linux
Installed from:    Archlinux Packages

While Dolphin is loading large or long-loading folders (like floppy drive, /usr/bin, /usr/lib) it freezes. When loading is done, it works normally again.
Comment 1 Peter Penz 2010-05-14 21:44:10 UTC
Thanks for the report. Could you please let us know which view mode you are using and whether you have turned on previews?
Comment 2 Nikita Churaev 2010-05-18 03:26:32 UTC
Icons, no previews.
Comment 3 Peter Penz 2010-05-18 08:15:22 UTC
Have you checked, whether increasing the maximum preview size helps? This can be done in Settings -> Configure Dolphin... -> General -> Previews: Maximum file size (BTW: the dialog has a little bit improved in KDE 4.5, as "Maximum file size" is not very clear).
Comment 4 Nikita Churaev 2010-05-19 07:39:14 UTC
Why should it help, I am not using previews. Anyways, 100Mb preview size didn't hellp at all.
Comment 5 Peter Penz 2010-05-19 10:43:57 UTC
Sorry, please ignore my comment #3: I mixed up this error-report with a similar report... 

Yes: This is already long on my TODO-list, but not easy to solve. It is not only Dolphin related, but involves very core kdelibs classes. E. g. loading /usr/bin is a kind of worst scenario, as the MIME-type for ~2000 files is unknown and must be determined by looking into the file. Of course this should not block Dolphin as done currently.
Comment 6 David Faure 2010-05-19 12:16:35 UTC
The mimetype determination is supposed to happen in a delayed manner. However it's quite easy for that to be broken, as soon as some code calls the method that determines the mimetype immediately. So I fix this bug every year or so ;)
This year, it seems the guilty code is KFileItem::overlays which calls KFileItem::isDesktopFile which calls KFileItem::determineMimeType...

#13 0x00007ffff6af62fd in KFileItem::determineMimeType (this=0x11f7310) at /d/kde/src/t/kdelibs/kio/kio/kfileitem.cpp:696
#14 0x00007ffff6afa782 in KFileItem::isDesktopFile (this=0x11f7310) at /d/kde/src/t/kdelibs/kio/kio/kfileitem.cpp:1467
#15 0x00007ffff6af7068 in KFileItem::overlays (this=0x11f7310) at /d/kde/src/t/kdelibs/kio/kio/kfileitem.cpp:822
#16 0x00007ffff6aeb2af in KDirModel::data (this=0xaaf9f0, index=..., role=1) at /d/kde/src/t/kdelibs/kio/kio/kdirmodel.cpp:686
#17 0x00007ffff76ac8ef in DolphinModel::data (this=0xaaf9f0, index=..., role=1) at /d/kde/src/t/kdebase/apps/dolphin/src/dolphinmodel.cpp:128
#18 0x00007ffff598af05 in QSortFilterProxyModel::data (this=0xaab170, index=..., role=1) at itemviews/qsortfilterproxymodel.cpp:1678
#19 0x00007ffff6b0d809 in QModelIndex::data (this=0x7fffffffb5b0, arole=1) at /d/qt/4/kde-qt-4.6/include/QtCore/../../src/corelib/kernel/qabstractitemmodel.h:398
#20 0x00007ffff6b09cd9 in KFileItemDelegate::Private::decoration (this=0xac04b0, option=..., index=...) at /d/kde/src/t/kdelibs/kio/kio/kfileitemdelegate.cpp:1095

I'll have a look at fixing it.
Comment 7 David Faure 2010-05-19 13:44:59 UTC
SVN commit 1128475 by dfaure:

Performance fix: Repair delayed mimetype determination: calling overlays should not do mimetype determination.
CCBUG: 237668


 M  +29 -18    kio/kfileitem.cpp  
 M  +8 -0      tests/kfileitemtest.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1128475
Comment 8 David Faure 2010-05-19 13:53:42 UTC
It's a bit better now, but there's still a big slowdown whenever a mimetype is determined. The code in KCategorizedView::dataChanged between BEGIN and END seems to be the culprit - I wonder if this code is really needed when not using "categorized view", but just a simple icon view?

#2  0x00007ffff4480127 in QMap<QModelIndex, QSortFilterProxyModelPrivate::Mapping*>::const_iterator::operator* (this=0x7fffffffb790) at
 ../../include/QtCore/../../src/corelib/tools/qmap.h:305
#3  0x00007ffff447fb5d in QSortFilterProxyModelPrivate::create_index (this=0xbe9850, row=2950, column=0, it=...) at itemviews/qsortfilterproxymodel.cpp:170
#4  0x00007ffff447b94d in QSortFilterProxyModel::index (this=0xc14280, row=2950, column=0, parent=...) at itemviews/qsortfilterproxymodel.cpp:1606
#5  0x00007ffff43fffe6 in QCommonListViewBase::modelIndex (this=0xc11300, row=2950) at ../../include/QtGui/private/../../../src/gui/itemviews/qlistview_p.h:463
#6  0x00007ffff43fcb37 in QIconModeViewBase::doBatchedItemLayout (this=0xc11300, info=..., max=2962) at itemviews/qlistview.cpp:2735   
#7  0x00007ffff43f6e43 in QListViewPrivate::doItemsLayout (this=0xc37c70, delta=2963) at itemviews/qlistview.cpp:1717
#8  0x00007ffff43f5c71 in QListView::doItemsLayout (this=0xbe9d50) at itemviews/qlistview.cpp:1460
#9  0x00007ffff43dcf2a in QAbstractItemViewPrivate::executePostedLayout (this=0xc37c70) at ../../include/QtGui/private/../../../src/gui/itemviews/qabstractitemview_p.h:212
#10 0x00007ffff43ff96c in QListViewPrivate::rectForIndex (this=0xc37c70, index=...) at ../../include/QtGui/private/../../../src/gui/itemviews/qlistview_p.h:344
#11 0x00007ffff43f4057 in QListView::rectForIndex (this=0xbe9d50, index=...) at itemviews/qlistview.cpp:1226
#12 0x00007ffff43f0bb3 in QListView::visualRect (this=0xbe9d50, index=...) at itemviews/qlistview.cpp:561
#13 0x00007ffff5ef1ea9 in KCategorizedView::visualRect (this=0xbe9d50, index=...) at /d/kde/src/t/kdelibs/kdeui/itemviews/kcategorizedview.cpp:549
#14 0x00007ffff5ef7b22 in KCategorizedView::dataChanged (this=0xbe9d50, topLeft=..., bottomRight=...) at /d/kde/src/t/kdelibs/kdeui/itemviews/kcategorizedview.cpp:1413
#15 0x00007fffe4fb1d14 in DolphinIconsView::dataChanged (this=0xbe9d50, topLeft=..., bottomRight=...) at /d/kde/src/t/kdebase/apps/dolphin/src/dolphiniconsview.cpp:139
#16 0x00007fffe4fb3ce7 in DolphinIconsView::qt_metacall (this=0xbe9d50, _c=QMetaObject::InvokeMetaMethod, _id=0, _a=0x7fffffffc0a0) at 
/d/kde/build/t/kdebase/apps/dolphin/src/dolphiniconsview.moc:85
#17 0x00007ffff517751f in QMetaObject::metacall (object=0xbe9d50, cl=QMetaObject::InvokeMetaMethod, idx=74, argv=0x7fffffffc0a0) at ker
nel/qmetaobject.cpp:237
#18 0x00007ffff518d9a9 in QMetaObject::activate (sender=0xc14280, m=0x7ffff54eb380, local_signal_index=0, argv=0x7fffffffc0a0) at kerne
l/qobject.cpp:3286
#19 0x00007ffff51f50c9 in QAbstractItemModel::dataChanged (this=0xc14280, _t1=..., _t2=...) at .moc/debug-shared/moc_qabstractitemmodel.cpp:148
#20 0x00007ffff447a277 in QSortFilterProxyModelPrivate::_q_sourceDataChanged (this=0xbe9850, source_top_left=..., source_bottom_right=.
..) at itemviews/qsortfilterproxymodel.cpp:1154
#21 0x00007ffff447ee9d in QSortFilterProxyModel::qt_metacall (this=0xc14280, _c=QMetaObject::InvokeMetaMethod, _id=5, _a=0x7fffffffc430
) at .moc/debug-shared/moc_qsortfilterproxymodel.cpp:128
#22 0x00007ffff6f4fb91 in KDirSortFilterProxyModel::qt_metacall (this=0xc14280, _c=QMetaObject::InvokeMetaMethod, _id=30, _a=0x7fffffff
c430) at /d/kde/build/t/kdelibs/kfile/kdirsortfilterproxymodel.moc:68
#23 0x00007fffe4fbf249 in DolphinSortFilterProxyModel::qt_metacall (this=0xc14280, _c=QMetaObject::InvokeMetaMethod, _id=30, _a=0x7ffff
fffc430) at /d/kde/build/t/kdebase/apps/dolphin/src/dolphinsortfilterproxymodel.moc:68
#24 0x00007ffff517751f in QMetaObject::metacall (object=0xc14280, cl=QMetaObject::InvokeMetaMethod, idx=30, argv=0x7fffffffc430) at kernel/qmetaobject.cpp:237
#25 0x00007ffff518d9a9 in QMetaObject::activate (sender=0xbe1640, m=0x7ffff54eb380, local_signal_index=0, argv=0x7fffffffc430) at kernel/qobject.cpp:3286
#26 0x00007ffff51f50c9 in QAbstractItemModel::dataChanged (this=0xbe1640, _t1=..., _t2=...) at .moc/debug-shared/moc_qabstractitemmodel.cpp:148
#27 0x00007ffff6afde2c in KDirModel::itemChanged (this=0xbe1640, index=...) at /d/kde/src/t/kdelibs/kio/kio/kdirmodel.cpp:635
#28 0x00007ffff6f7e133 in KFilePreviewGenerator::Private::dispatchIconUpdateQueue (this=0xbf5290) at /d/kde/src/t/kdelibs/kfile/kfilepreviewgenerator.cpp:709
#29 0x00007ffff6f80db2 in KFilePreviewGenerator::qt_metacall (this=0xc4b2d0, _c=QMetaObject::InvokeMetaMethod, _id=5, _a=0x7fffffffc6a0
) at /d/kde/build/t/kdelibs/kfile/kfilepreviewgenerator.moc:98
Comment 9 Peter Penz 2010-05-19 14:13:15 UTC
Thanks a lot David for your investigations, I'll check the code in KCategorizedView::dataChanged() today in the evening. I'm very, very sure, that this code is only needed if the categorized view has been enabled.
Comment 10 David Faure 2010-05-19 15:00:12 UTC
OK, thanks. Thinking about it further, though, the time is spent in the re-layout of listview items after dataChanged was emitted, it would happen later on even if this code was not there, I think. Still worth cleaning up, but it might not have much effect on performance.

Breaking into the process later on I saw much time spent in
KIconEngine::actualSize, which currently loads the actual icon just to find its
size. I'll make a reviewboard request for that one.
Comment 11 David Faure 2010-05-19 15:26:38 UTC
http://reviewboard.kde.org/r/4052/
Comment 12 Peter Penz 2010-05-19 18:46:24 UTC
SVN commit 1128571 by ppenz:

Performance optimization: Check whether the categorization feature is used, before adjusting categorization specific properties

CCBUG: 237668

 M  +13 -2     kcategorizedview.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1128571
Comment 13 Peter Penz 2010-05-19 18:48:47 UTC
@David: I've applied your patch from http://reviewboard.kde.org/r/4052/ locally and it seems to work great :-) If I'd see any icon size specific issues, I'd let you know.
Comment 14 Peter Penz 2010-08-17 11:41:30 UTC
I verified this issue now with KDE SC 4.5.0 and loading /usr/bin, /usr/lib is very fast now.