From kde-core-devel Fri Jul 21 12:05:39 2000 From: Geert Jansen Date: Fri, 21 Jul 2000 12:05:39 +0000 To: kde-core-devel Subject: KIconLoader patch X-MARC-Message: https://marc.info/?l=kde-core-devel&m=96418758717507 Hi! I've been investigating various optimisations to KIconLoader. The final results are: [kde2] greet:~/kde/CVS/kdelibs/kdecore> ./stats konq-*-nopath file: konq-4img-nopath datapoints: 99 mean value: 2352.192627 std. dev.: 30.627594 file: konq-noimg-nopath datapoints: 100 mean value: 2374.019287 std. dev.: 19.582916 Conclusions: * The best results I found are have an iconloder with an image cache of 4 images. A bigger cache didn't have a positive effect on konqy's startup time. The gain is a shallow 22 ms. On NFS, I expect to see a much bigger performance impact. * A path cache didn't have any influence. The patch implementing the image cache is appended to this email. If it's ok with you, I'd like to commit it. Greetings, Geert Index: kiconloader.cpp =================================================================== RCS file: /home/kde/kdelibs/kdecore/kiconloader.cpp,v retrieving revision 1.137 diff -u -r1.137 kiconloader.cpp --- kiconloader.cpp 2000/07/19 11:17:11 1.137 +++ kiconloader.cpp 2000/07/21 11:42:43 @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -126,7 +127,7 @@ KIconThemeNode *mpThemeRoot; KStandardDirs *mpDirs; KIconEffect mpEffect; - QDict imgDict; + QCache imgCache; }; @@ -199,10 +200,12 @@ for (QStringList::ConstIterator it = dirs.begin(); it != dirs.end(); it++) d->mpDirs->addResourceDir("appicon", *it); + d->imgCache.setMaxCost(4); + d->imgCache.setAutoDelete(true); + QString dbgString = "Theme tree: "; d->mpThemeRoot->printTree(dbgString); kdDebug(264) << dbgString << endl; - } KIconLoader::~KIconLoader() @@ -455,9 +458,8 @@ // Generate a unique cache key for the icon. - key = "$kico_"; - key += name; key += "_"; - key += QString().setNum(size); key += "_"; + QString basekey = QString("%1_%2_").arg(name).arg(size); + key = "$kico_"; key += basekey; if (group >= 0) { key += d->mpEffect.fingerprint(group, state); @@ -496,10 +498,20 @@ if (inCache) return pix; - QImage img(icon.path); - if (img.isNull()) - return pix; - + // Try to load image from the image cache. + QImage *imgptr = d->imgCache.find(basekey); + if (imgptr == 0L) + { + imgptr = new QImage(icon.path); + if (imgptr->isNull()) + { + delete imgptr; + return pix; + } + d->imgCache.insert(basekey, imgptr); + } + QImage img = *imgptr; // copy, image might be changed. + // Blend in all overlays if (overlay) { @@ -537,9 +549,12 @@ QImage *KIconLoader::loadOverlay(const QString &name, int size) const { - QImage *image = d->imgDict.find(name); + QString key = QString("%1_%2_").arg(name).arg(size); + QImage *image = d->imgCache.find(key); if (image != 0L) + { return image; + } KIcon icon = findMatchingIcon(name, size); if (!icon.isValid()) @@ -548,7 +563,7 @@ return 0L; } image = new QImage(icon.path); - d->imgDict.insert(name, image); + d->imgCache.insert(key, image); return image; }