KFileItem, mime types, and icons

Frank Reininghaus frank78ac at googlemail.com
Thu Jun 6 12:20:06 BST 2013


Hi David,

I'm currently trying to make Dolphin waste less resources when loading
icons, previews, and other information that might be expensive to
retrieve, and also to reduce the irritations caused by "unknown" icons
appearing in the view.

My following question might be stupid, but I'm not really an expert
(most of my icon loading/mime type knowledge comes from reading
Peter's code), and I want to make sure that I don't mess things up, so
I thought asking the expert for advice might be a good idea :-)


1. My observations

The thing is that Peter's code *always* calls
KFileItem::determineMimeType() before calling KFileItem::iconName().

Now I wondered if that is really necessary, so I tried the following:
called iconName() and iconOverlays() for all items that were received
from KDirLister when entering a folder, measured how much time that
takes, and then called determineMimeType() for all these items, and
measured again.

It turns out that icon loading is often *much* faster than determining
the mime types, especially in my favourite "see how it works with many
real-world items" test cases /usr/bin/, /usr/include/, and /usr/lib64.
The icons look OK even though the mime type of many files was
apparently not known while the icon was loaded.


2. My conclusions

I think that we should do the following:

(a) When we try to determine icons for the visible items synchronously
for 200 ms (we always do that when entering a folder or new items are
inserted), we should just call iconName(), maybe iconOverlays(), but
definitely not determineMimeType() (unless we sort by type).

(b) Later on, when we look at each item in the visible range (and
those near the visible range or at the top and bottom of the list)
asynchronously, we call determineMimeType() and update the icon.

This would greatly reduce the risk that 200 ms are insufficient for
loading the visible icons, which results in "unknown" icons being
shown to the user, which then only get replaced asynchronously and
slowly.


What do you think?

Thanks and best regards,
Frank




More information about the kfm-devel mailing list