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

List:       kde-core-devel
Subject:    KConfig sync speedup patch rev 1
From:       Ian Reinhart Geiser <geiseri () yahoo ! com>
Date:       2003-09-09 13:09:38
[Download RAW message or body]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,
	At n7y I worked out this patch with the help of david.  It seems to speed up 
some apps when i measure them with calltree.  The issue was that before this 
patch every time you call sync the config file is reparsed.  This patch 
causes the config file not to be reparsed unless it has changed on disk since 
the last write.

	In kmail with calltree without it I seem to see 10% of startup time spent in 
KConfigINIBackend::sync(), where as after the patch it only spends about 
7%....  Im still not sure if these numbers are accurate, so im hopeful others 
can test, modify this patch.

	The idea is that a stat and compair of QDateTime is faster than the reparse.  

	Thanks
	-ian reinhart geiser
- -- 
- --:Ian Reinhart Geiser <geiseri@yahoo.com>
- --:Public Key: http://geiseri.myip.org/~geiseri/publickey.asc
- --:Public Calender: http://geiseri.myip.org/~geiseri/publicevents.ics
- --:Jabber: geiseri@geiseri.myip.org
- --:Be an optimist -- at least until they start moving animals in 
- --:   pairs to Cape Canaveral. ~ Source Unknown
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE/XdEXPy62TRm8dvgRAu8JAJ9BruJ9p2FkCMrjujSS7pkscEu6JwCbB8oj
HppkcHnWs1fnubhF93NyVGY=
=J2N6
-----END PGP SIGNATURE-----

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

Index: kconfigbackend.h
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kconfigbackend.h,v
retrieving revision 1.30
diff -u -r1.30 kconfigbackend.h
--- kconfigbackend.h	30 Aug 2003 07:33:48 -0000	1.30
+++ kconfigbackend.h	9 Sep 2003 13:08:53 -0000
@@ -24,6 +24,7 @@
 
 #include "kconfigdata.h"
 #include <kconfigbase.h>
+#include <qdatetime.h>
 #include "kdemacros.h"
 
 class QFile;
@@ -280,6 +281,7 @@
   virtual void virtual_hook( int id, void* data );
 private:
   KConfigINIBackEndPrivate *d;
+  QDateTime bModTime;
 };
 
 #endif
Index: kconfigbackend.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kconfigbackend.cpp,v
retrieving revision 1.82
diff -u -r1.82 kconfigbackend.cpp
--- kconfigbackend.cpp	7 Sep 2003 20:37:32 -0000	1.82
+++ kconfigbackend.cpp	9 Sep 2003 13:08:54 -0000
@@ -198,6 +198,7 @@
 
 bool KConfigINIBackEnd::parseConfigFiles()
 {
+  //qDebug("Trying to parse %s\n", mLocalFileName.latin1());
   // Check if we can write to the local file.
   mConfigState = KConfigBase::ReadOnly;
   if (!mLocalFileName.isEmpty() && !pConfig->isReadOnly())
@@ -295,6 +296,9 @@
   if (bFileImmutable)
      mConfigState = KConfigBase::ReadOnly;
 
+  QFileInfo info(mLocalFileName);
+  bModTime = info.lastModified();
+
   return true;
 }
 
@@ -311,6 +315,29 @@
 #endif
 #endif
 
+#include <execinfo.h>
+#include <stdlib.h>
+
+static QString qBacktrace( int levels = -1 )
+{
+    QString s;
+    void* trace[256];
+    int n = backtrace(trace, 256);
+    char** strings = backtrace_symbols (trace, n);
+
+    if ( levels != -1 )
+        n = QMIN( n, levels );
+    s = "[\n";
+
+    for (int i = 0; i < n; ++i)
+        s += QString::number(i) +
+             QString::fromLatin1(": ") +
+             QString::fromLatin1(strings[i]) + QString::fromLatin1("\n");
+    s += "]\n";
+    free (strings);
+    return s;
+}
+
 void KConfigINIBackEnd::parseSingleConfigFile(QFile &rFile,
 					      KEntryMap *pWriteBackMap,
 					      bool bGlobal, bool bDefault)
@@ -322,9 +349,9 @@
 
    //using kdDebug() here leads to an infinite loop
    //remove this for the release, aleXXX
-   //qWarning("Parsing %s, global = %s default = %s",
-   //           rFile.name().latin1(), bGlobal ? "true" : "false", bDefault ? "true" : "false");
-
+   //qDebug("Parsing %s, global = %s default = %s\n",
+    //          rFile.name().latin1(), bGlobal ? "true" : "false", bDefault ? "true" : "false");
+   //qDebug("%s",qBacktrace().latin1());
    QCString aCurrentGroup("<default>");
 
    const char *s, *eof;
@@ -712,8 +739,20 @@
 {
   bool bEntriesLeft = false;
   bFileImmutable = false;
+  // Check if the file has been updated.
+  bool isMod = false;
   if (mergeFile)
   {
+	QFileInfo info(*mergeFile);
+	if (info.lastModified() > bModTime)
+	{
+		isMod = true;
+	}
+  }
+
+  if (mergeFile && isMod)
+  {
+
     // Read entries from disk
     if (mergeFile->open(IO_ReadOnly))
     {
@@ -825,6 +864,7 @@
      if (pConfigFile->status() != 0)
      {
         delete pConfigFile;
+        pConfigFile = 0L;
         return bEntriesLeft;
      }
 
@@ -870,11 +910,16 @@
         pConfigFile->close();
      }
      delete pConfigFile;
+     pConfigFile = 0L;
   }
   else
   {
      fclose(pStream);
   }
+
+  // Update time stamp
+  QFileInfo info(filename);
+  bModTime = info.lastModified();
 
   return bEntriesLeft;
 }


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

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