The font caching in qt2/qfont_loader.C uses a std::map which shows on gprof profiles (around 16% with all optimizations on and no assertions). It appears that Qt has its own font caching mechanism since version 3.1.0. With the attached patch, displaying is a bit faster (and the nice thing is that it is done by removing code...)
Before patch: fantomas: time ./lyx -x 'command-sequence file-open /local/lasgoutt/profbuild/src/UserGuide.lyx ; repeat 200 screen-down ; lyx-quit' 2>/dev/null real 0m11.464s user 0m5.270s sys 0m0.080s After patch: fantomas: time ./lyx -x 'command-sequence file-open /local/lasgoutt/profbuild/src/UserGuide.lyx ; repeat 200 screen-down ; lyx-quit' 2>/dev/null real 0m10.595s user 0m4.430s sys 0m0.070s I would be interested to know what happens with LyX/Mac and LyX/Win, though. Lars, would you consider such a patch for 1.4.0? JMarc
Index: src/frontends/qt2/ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/ChangeLog,v retrieving revision 1.759 diff -u -p -r1.759 ChangeLog --- src/frontends/qt2/ChangeLog 21 Mar 2005 08:31:54 -0000 1.759 +++ src/frontends/qt2/ChangeLog 5 Apr 2005 12:09:55 -0000 @@ -1,3 +1,8 @@ +2005-04-04 Jean-Marc Lasgouttes <[EMAIL PROTECTED]> + + * qfont_loader.C (charwidth): + * qfont_loader.h: do no do font width caching with Qt >= 3.1.0 + 2005-03-18 Georg Baum <[EMAIL PROTECTED]> * ui/QPrefLatexModule.ui: fix layout Index: src/frontends/qt2/qfont_loader.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/qfont_loader.C,v retrieving revision 1.53 diff -u -p -r1.53 qfont_loader.C --- src/frontends/qt2/qfont_loader.C 27 Jan 2005 21:05:36 -0000 1.53 +++ src/frontends/qt2/qfont_loader.C 5 Apr 2005 12:09:55 -0000 @@ -375,6 +375,9 @@ qfont_loader::font_info * qfont_loader:: int qfont_loader::charwidth(LyXFont const & f, Uchar val) { +// Starting with version 3.1.0, Qt/X11 does its own caching of +// character width, so it is not necessary to provide ours. +#if QT_VERSION < 0x030100 font_info * fi = getfontinfo(f); font_info::WidthCache::const_iterator cit = fi->widthcache.find(val); @@ -384,6 +387,9 @@ int qfont_loader::charwidth(LyXFont cons int const w = fi->metrics.width(QChar(val)); fi->widthcache[val] = w; return w; +#else + return getfontinfo(f)->metrics.width(QChar(val)); +#endif } Index: src/frontends/qt2/qfont_loader.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/qfont_loader.h,v retrieving revision 1.15 diff -u -p -r1.15 qfont_loader.h --- src/frontends/qt2/qfont_loader.h 19 Jan 2005 15:03:30 -0000 1.15 +++ src/frontends/qt2/qfont_loader.h 5 Apr 2005 12:09:55 -0000 @@ -13,7 +13,9 @@ #define QFONTLOADER_H +#if QT_VERSION < 0x030100 #include <map> +#endif #include "encoding.h" #include "lyxfont.h" @@ -65,9 +67,11 @@ private: /// metrics on the font QFontMetrics metrics; +#if QT_VERSION < 0x030100 typedef std::map<Uchar, int> WidthCache; /// cache of char widths WidthCache widthcache; +#endif }; /// get font info (font + metrics) for the given LyX font. Does not fail.