[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: [PATCH] Cache returned KIconLoader pixmaps in 4.5.2
From:       Matthias Fuchs <mat69 () gmx ! net>
Date:       2010-09-13 9:09:15
Message-ID: 201009131109.31021.mat69 () gmx ! net
[Download RAW message or body]

[Attachment #2 (multipart/mixed)]


Am Montag 13 September 2010, 04:57:18 schrieb Michael Pyne:
> On Monday, September 13, 2010 00:20:40 Matthias Fuchs wrote:
> > Works really great now. I have a question though:
> > 
> > When running my small test program the icon gets cached and then reused,
> > though if I run the test again -- i.e. start the program again -- it gets
> > also cached again and then reused, but shouldn't it still be in the cache
> > from running the program the first time?
> > Or does the cache gets cleaned up very fast?
> 
> Define "cache". There are two:
> 
> 1. A process-shared cache, but the catch is that the data must still be
> decoded from PNG (which is how both QImage and QPixmap stream it to
> storage). 2. A process-local pixmap cache. This essentially stores
> references to the QPixmap that had been read from cache 1 so that it is
> easy to refer to in the future. These pixmaps are already in either X
> server or GPU memory which is why they're much faster.

Is there a specific reason the pixmap cache is process-local instead of 
process-shared? The reason I am asking this is that the creation is very 
expensive as noticed before.


In any case the attached patch speeds up a warm pixmap cache by 25%, I know 
looking up is very fast already but imo this patch does not make the code 
harder to understand but still gives a small speed gain.


Cheers!
matthias

["kiconloader.diff" (text/x-patch)]

Index: kdeui/icons/kiconloader.cpp
===================================================================
--- kdeui/icons/kiconloader.cpp	(Revision 1174567)
+++ kdeui/icons/kiconloader.cpp	(Arbeitskopie)
@@ -37,6 +37,7 @@
 #include <QtCore/QBuffer>
 #include <QtCore/QDataStream>
 #include <QtCore/QByteArray>
+#include <QtCore/QStringBuilder>
 #include <QtGui/QIcon>
 #include <QtGui/QPainter>
 #include <QMovie>
@@ -756,26 +757,9 @@
 QString KIconLoaderPrivate::makeCacheKey(const QString &name, KIconLoader::Group group,
                                          const QStringList &overlays, int size, int state) const
 {
-    // The KSharedDataCache is shared so add some namespacing.
-    QString key;
-
-    if (group == KIconLoader::User) {
-        key = QLatin1String("$kicou_");
-    }
-    else {
-        key = QLatin1String("$kico_");
-    }
-
-    key.append(QString("%1_%2_%3").arg(name).arg(size).arg(overlays.join("_")));
-
-    if (group >= 0) {
-        key.append(mpEffect.fingerprint(group, state));
-    }
-    else {
-        key.append(QLatin1String("noeffect"));
-    }
-
-    return key;
+    return (group == KIconLoader::User ? QLatin1String("$kicou_") : QLatin1String("$kico_")) %
+           name % QLatin1Char('_') % QString::number(size) % QLatin1Char('_') % overlays.join("_") %
+           (group >= 0 ? mpEffect.fingerprint(group, state) : QString("noeffect"));//QString here, since \
ternary operator does not support different clases  }
 
 QImage KIconLoaderPrivate::createIconImage(const QString &path, int size)


["signature.asc" (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic