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

List:       kde-optimize
Subject:    kdeinit hack for faster apps startup and more shared memory
From:       Lubos Lunak <l.lunak () suse ! cz>
Date:       2004-06-30 15:58:31
Message-ID: 200406301758.31612.l.lunak () suse ! cz
[Download RAW message or body]

Hello,

 KDE3.2 got quite good reputation for being faster than KDE3.1. And since 
(AFAIK) there haven't been any noticeable optimizations for KDE3.3, I'd like 
to get in 3.3 at least the attached kdeinit hack. Done by Michael Matz, 
tested by Coolo, fixed by me :).

 The trick is that there are several things done on each application startup, 
and these things are(?) safe to do even in kdeinit before forking. Which 
means after the fork() and dlopen() of the application they'll be already 
initialized, thus reducing app startup time, and since the initialization 
will be done before fork() and fork() is copy-on-write, there will be also 
less used memory.

 Two of the pre-initialized things are fontconfig and XIM, which are currently 
responsible for a significant amount of memory used by KDE, as can be seen in 
http://lists.kde.org/?l=kde-optimize&m=108696117008113&w=2 . It doesn't 
remove the problem completely though (looks like many pages become dirty 
anyway, memory allocated by fontconfig is very fragmented), so there is still 
need for a real fix in the libs, but this is better than nothing.

 Coolo says he's been using this patch for months without noticing any 
problem, except for kdeinit apps not picking up fonts changes, which should 
be now fixed. It makes KDE startup faster (15s->14s), saves some memory (5+ 
MiB) and makes start of kdeinit apps faster (~125 ms). That's Athlon 1600+ 
(i.e. 1,4Ghz), KDE started was just plain KDE with 2xKonsole+1xKWrite.

 End of the informative part.

- Any reason against shipping this with KDE3.3?

- When exactly should it be enabled (i.e. configure checks)? Are there still 
Qt builds which don't use Xft+fontconfig, or would it be ok to simply 
hardcode it there?

- Looks like fontconfig doesn't notice any new fonts when the app is already 
running, so kdeinit needs to do an up-to-date check before launching new 
apps. Fontconfig has FcInitBringUptoDate(), but I used instead the 
FcConfigUptoDate() + FcInitReinitialize() combo, which avoids the interval 
when fontconfig doesn't really check anything and assumes nothing has 
changed. There also seems to be a bug in fontconfig causing 
FcConfigUpToDate() always returning false causing rebuilding all the time, 
which means with the current fontconfig the initialization is just moved from 
the apps to kdeinit. I'll submit the attached patch to fontconfig devels and 
see.

- Comments?


 PS: Another thing worth considering might be prescanning 
(http://lists.kde.org/?l=kde-optimize&m=107954681501259&w=2), at least with 
the simple app that's attached to that mail. If added to the right place in 
KDM and run while the user is typing login information, this could even have 
no negative effect. The kernel-supported solution seems to be too complicated 
for KDE3.3.

-- 
Lubos Lunak
KDE developer
---------------------------------------------------------------------
SuSE CR, s.r.o.  e-mail: l.lunak@suse.cz , l.lunak@kde.org
Drahobejlova 27  tel: +420 2 9654 2373
190 00 Praha 9   fax: +420 2 9654 2374
Czech Republic   http://www.suse.cz/

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

--- kinit.cpp.sav	2004-05-28 17:34:36.000000000 +0200
+++ kinit.cpp	2004-06-30 17:24:51.320719320 +0200
@@ -42,6 +42,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <locale.h>
 
 #include <qstring.h>
 #include <qfile.h>
@@ -49,6 +50,7 @@
 #include <qfileinfo.h>
 #include <qtextstream.h>
 #include <qregexp.h>
+#include <qfont.h>
 #include <kinstance.h>
 #include <kstandarddirs.h>
 #include <kglobal.h>
@@ -1234,6 +1236,9 @@ static void handle_launcher_request(int 
        free(request_data);
 }
 
+extern "C" int FcConfigUptoDate(void*);
+extern "C" void FcInitReinitialize();
+
 static void handle_requests(pid_t waitForPid)
 {
    int max_sock = d.wrapper;
@@ -1316,6 +1321,8 @@ static void handle_requests(pid_t waitFo
          int sock = accept(d.wrapper, (struct sockaddr *)&client, &sClient);
          if (sock >= 0)
          {
+            if( !FcConfigUptoDate(NULL))
+               FcInitReinitialize();
             if (fork() == 0)
             {
                 close_fds();
@@ -1332,6 +1339,8 @@ static void handle_requests(pid_t waitFo
          int sock = accept(d.wrapper_old, (struct sockaddr *)&client, &sClient);
          if (sock >= 0)
          {
+            if( !FcConfigUptoDate(NULL))
+               FcInitReinitialize();
             if (fork() == 0)
             {
                 close_fds();
@@ -1584,6 +1593,10 @@ static void secondary_child_handler(int)
    waitpid(-1, 0, WNOHANG);
 }
 
+extern "C" void XftInit (const char*);
+extern "C" void XftInitFtLibrary (void);
+
+
 int main(int argc, char **argv, char **envp)
 {
    int i;
@@ -1742,6 +1755,20 @@ int main(int argc, char **argv, char **e
    X11fd = initXconnection();
 #endif
 
+   {
+      XftInit(0);
+      XftInitFtLibrary();
+      QFont::initialize();
+      setlocale (LC_ALL, "");
+      setlocale (LC_NUMERIC, "C");
+      if (XSupportsLocale ())
+      {
+         // Similar to QApplication::create_xim()
+	 // but we need to use our own display
+	 XOpenIM (X11display, 0, 0, 0);
+      }
+   }
+
    for(i = 1; i < argc; i++)
    {
       if (safe_argv[i][0] == '+')

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

--- fccfg.c.sav	2004-02-07 08:13:48.000000000 +0100
+++ fccfg.c	2004-06-30 13:21:02.818589672 +0200
@@ -166,9 +166,9 @@ FcConfigUptoDate (FcConfig *config)
 	    return FcFalse;
     }
     config_time = FcConfigNewestFile (config->configFiles);
-    font_time = FcConfigNewestFile (config->configDirs);
+    font_time = FcConfigNewestFile (config->fontDirs);
     if ((config_time.set && config_time.time - config->rescanTime > 0) ||
-	(font_time.set && font_time.time - config->rescanTime) > 0)
+	(font_time.set && font_time.time - config->rescanTime > 0))
     {
 	return FcFalse;
     }


_______________________________________________
Kde-optimize mailing list
Kde-optimize@kde.org
https://mail.kde.org/mailman/listinfo/kde-optimize


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

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