KFilterDev changes from KDE3

David Faure faure at kde.org
Thu Mar 19 19:24:25 GMT 2009


On Tuesday 17 March 2009, Pino Toscano wrote:
> Alle martedì 17 marzo 2009, Martin Koller ha scritto:
> > On Tuesday 17 March 2009, David Faure wrote:
> > > > Well, I know the mimetype, but as I do a backup of a _lot_ of files,
> > > > isn't the overhead too high to again and again calling
> > > > findFilterByMimeType() (as the mimetype will never change during the
> > > > complete backup) ?
> > >
> > > KFilterBase::findFilterByMimeType only loads a mimetype from ksycoca
> > > (that's supposed to be really fast, just a dict lookup and a bit of
> > > deserialization) and compares strings. If it really turns out to be a
> > > bottleneck, we could add a cache in KFilterDev so that it remembers the
> > > last requested mimetype and the KFilterBase that was created for it (with
> > > care not to leak or double-delete kfilterbases...). In any case this can
> > > and should be handled internally in KFilterDev.
> >
> > I now run a first test:
> >
> > ~18000 files processed: KDE4 3:02 Minutes, KDE3 2:12 Minutes ...
> >
> > It _is_ a bottleneck, as this was just a small test.
> 
> What about the attached patch?
> This should avoid the KMimeType deserialization in case the specified mimetype 
> is either exactly the one of gzip or bzip2, otherwise searching doing the 
> mimetype lookup as before.

Good solution with the current API indeed.

But in fact this is a more general performace problem -- we should have a faster way of checking 
mimetype inheritance without deserializing a complete mimetype definition first.
That's already an item on my todo list, actually (iirc this came from profiling "show/hide hidden files" in 
KFileDialog which was hitting that code path quite a lot, in a $HOME with many hidden files). 
My idea was to add something like
  static bool KMimeType::mimeTypeInherits(const QString& mimeType, const QString& possibleParent)
(better name welcome), which could either look up a specific ksycoca hash, or an in-memory hash
that contains the result of the parsing of the "subclasses" files from shared-mime-info.
(First solutions eats less memory but makes kbuildsycoca4 take even longer, even though probably
not much).

Anyway, won't get that done today, so feel free to commit your patch meanwhile. I'll port it
with the rest when/if I implement mimeTypeInherits.

-- 
David Faure, faure at kde.org, sponsored by Qt Software @ Nokia to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).




More information about the kde-core-devel mailing list