[PATCH] speedup in KMimeTypeFactory?

Matt Rogers mattr at kde.org
Mon Oct 20 03:55:57 BST 2008

On Sun, Oct 19, 2008 at 04:23:31PM +0200, Olivier Goffart wrote:
> Le dimanche 19 octobre 2008, Matt Rogers a écrit :
> > Hi,
> >
> > The attached patch makes some changes to the matchFileName function in
> > kmimetypefactory.cpp which gets called a lot, especially when browsing
> > files in the file manager when trying to open a file.
> >
> > Depending on how you read the callgrind output, it's either a 5% (incl.
> > column) speedup or a 0.5% (self column) speedup. I can't remember which is
> > the more important number.
> The 'incl' is the most important.  The self doesn't matter at all (it's 
> included in the 'incl' anyway)
> I would say that what you have to compare is the 'Incl.' absolute cost divided 
> by the 'Called'

Thanks for the info.

> Caching the indexOf('[') certainly helps.
> But changing from the operator[] to startsWith/endsWith is probably slower 
> (the operator[] is inline and fast, while endsWith do lot of comparison and 
> don't know that we are comparing only one byte)

ok, i'll change that and reprofile. I had compiled with -fno-inline, so that's
probably why I see the skew. There are startsWith and endsWith overrides that
do take a QChar rather than a QString, and when I looked, it did look like
they knew we were comparing one byte.

> I don't know if the static QChar really helps.

It saved several hundred thousand QChar allocations, because the function is
called so much. 


More information about the kde-core-devel mailing list