From kde-core-devel Tue Sep 09 13:09:38 2003 From: Ian Reinhart Geiser Date: Tue, 09 Sep 2003 13:09:38 +0000 To: kde-core-devel Subject: KConfig sync speedup patch rev 1 X-MARC-Message: https://marc.info/?l=kde-core-devel&m=106311326417205 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--Boundary-00=_SEdX/2Ix6TSytZJ" --Boundary-00=_SEdX/2Ix6TSytZJ Content-Type: Text/Plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline =2D----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, At n7y I worked out this patch with the help of david. It seems to speed = up=20 some apps when i measure them with calltree. The issue was that before thi= s=20 patch every time you call sync the config file is reparsed. This patch=20 causes the config file not to be reparsed unless it has changed on disk sin= ce=20 the last write. In kmail with calltree without it I seem to see 10% of startup time spent = in=20 KConfigINIBackend::sync(), where as after the patch it only spends about=20 7%.... Im still not sure if these numbers are accurate, so im hopeful othe= rs=20 can test, modify this patch. The idea is that a stat and compair of QDateTime is faster than the repars= e. =20 Thanks -ian reinhart geiser =2D --=20 =2D --:Ian Reinhart Geiser =2D --:Public Key: http://geiseri.myip.org/~geiseri/publickey.asc =2D --:Public Calender: http://geiseri.myip.org/~geiseri/publicevents.ics =2D --:Jabber: geiseri@geiseri.myip.org =2D --:Be an optimist -- at least until they start moving animals in=20 =2D --: pairs to Cape Canaveral. ~ Source Unknown =2D----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE/XdEXPy62TRm8dvgRAu8JAJ9BruJ9p2FkCMrjujSS7pkscEu6JwCbB8oj HppkcHnWs1fnubhF93NyVGY=3D =3DJ2N6 =2D----END PGP SIGNATURE----- --Boundary-00=_SEdX/2Ix6TSytZJ Content-Type: text/x-diff; charset="us-ascii"; name="kconfigsync.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="kconfigsync.patch" 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 +#include #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 +#include + +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(""); 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; } --Boundary-00=_SEdX/2Ix6TSytZJ--