Mimetype optimization
David Faure
faure at kde.org
Tue Apr 22 23:29:55 CEST 2008
On Tuesday 22 April 2008, Jakub Stachowski wrote:
> Dnia wtorek, 22 kwietnia 2008, David Faure napisał:
> > On Tuesday 22 April 2008, Jakub Stachowski wrote:
> > > Hello,
> > >
> > > profiling dolphin while opening /usr/bin shows that about 35% of time is
> > > spent in QRegExp matching called by kmimefactory.cpp: matchFileName. This
> > > function already contains optimizations: for some simple (but popular)
> > > patterns like *.something or something* it uses direct comparision
> > > instead of QRegExp big gun. It looks like:
> > > if (pattern like *.something && filename long enough to match the
> > > pattern) compare directly;.
> > > However for short names (lots of them in /usr/bin) it often falls back to
> > > slow path. Attached patch changes is to:
> > > if (pattern like *.something) {
> > > if (filename not long enough to match) return false;
> > > else compare directly;
> > > }
> > >
> > > and detects patterns without wildcards (is checking for *,? and ]
> > > enough?)
> > >
> > > Results (measured by callgrind):
> > > Unpatched, for 179 calls to KMimeTypeFactory::findFromFileName
> > > - 5554 calls to QRegExp::exactMatch, which accounts for 35% of CPU time
> > >
> > > Patched, for 150 calls to KMimeTypeFactory::findFromFileName
> > > - QRegExp matched 13 times. findFromFileName takes 0.67% of CPU time
> >
> > Wow, excellent. Great find.
> > If the kdecore/tests/kmimetypetest unit test still passes, please commit :)
>
> Actually I get two failures (at lines 297 and 619, both related to *.doc) with
> and without the patch. But nothing changed, so I'm commiting.
With which version of shared-mime-info?
--
David Faure, faure at kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).
More information about the Kde-optimize
mailing list