Remove width cache for Qt 4 frontend. Total time for loading UserGuide + 250 x page down is
4.42s with map based font cache 3.46s with vector based font cache 3.44s without fontcache 3.18s without fontcache and inlined QLFontInfo::metrics Patch for the latter attached. Note also that ucs4_to_qstring is currently more expensive than rowBreakPoint() [which was actually the place I intended to work on...]: Flat profile: Each sample counts as 0.01 seconds. % cumulative self self total time seconds seconds calls s/call s/call name 7.08 0.23 0.23 1855291 0.00 0.00 font_metrics::width(wchar_t const*, unsigned int, LyXFont const&) 6.29 0.43 0.20 166256 0.00 0.00 LyXText::getFont(Paragraph const&, int) const 5.97 0.62 0.19 1896072 0.00 0.00 ucs4_to_qstring(wchar_t const*, unsigned int) 5.66 0.80 0.18 259 0.00 0.00 Buffer::buildMacros() 3.14 0.90 0.10 13891 0.00 0.00 LyXText::rowBreakPoint(int, Row&) const 2.20 0.97 0.07 13891 0.00 0.00 LyXText::setRowWidth(int, Row&) const 2.04 1.03 0.07 329379 0.00 0.00 LyXFont::LyXFont() 1.89 1.09 0.06 397568 0.00 0.00 BufferParams::getFont() const 1.26 1.13 0.04 1709232 0.00 0.00 DocIterator::inTexted() const 1.26 1.17 0.04 1236188 0.00 0.00 DocIterator::inMathed() const 1.26 1.21 0.04 439712 0.00 0.00 operator==(LyXFont::FontBits const&, LyXFont::FontBits const&) 1.26 1.25 0.04 308704 0.00 0.00 boost::crc_optimal<32u, 79764919u, 4294967295u, 4294967295u, true, true>::process_block(void const*, void const* ) 1.26 1.29 0.04 54284 0.00 0.00 (anonymous namespace)::RowPainter::paintChars(int&, LyXFont, bool, bool) 1.26 1.33 0.04 48183 0.00 0.00 LyXText::leftMargin(int, int) const 1.26 1.37 0.04 21317 0.00 0.00 LyXLex::Pimpl::next(bool) 1.26 1.41 0.04 10913 0.00 0.00 lyx::from_ascii(char const*) 1.10 1.45 0.04 2895302 0.00 0.00 InsetBase::inMathed() const 1.10 1.48 0.04 1770316 0.00 0.00 LyXText::singleWidth(Paragraph const&, int, wchar_t, LyXFont const&) const 0.94 1.51 0.03 183313 0.00 0.00 Paragraph::setFont(int, LyXFont const&) 0.94 1.54 0.03 64710 0.00 0.00 LyXText::getLabelFont(Paragraph const&) const 0.94 1.57 0.03 61943 0.00 0.00 char* std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_S_construct<__gnu_cxx::__normal_i I will apply the patch tomorrow evening unless I get objections or somebody else is faster. Andre'
Index: FontLoader.C =================================================================== --- FontLoader.C (revision 15203) +++ FontLoader.C (working copy) @@ -44,9 +44,6 @@ using std::string; -FontLoader::~FontLoader() { -} - namespace { struct symbol_font { @@ -219,7 +216,6 @@ QLFontInfo::QLFontInfo(LyXFont const & f) : metrics(font) { - string const pat = symbolFamily(f.family()); if (!pat.empty()) { bool tmp; @@ -287,24 +283,6 @@ } -int QLFontInfo::width(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 defined (USE_LYX_FONTCACHE) - QLFontInfo::WidthCache::const_iterator cit = widthcache.find(val); - if (cit != widthcache.end()) - return cit->second; - - int const w = metrics.width(QChar(val)); - widthcache[val] = w; - return w; -#else - return metrics.width(QChar(val)); -#endif -} - - bool FontLoader::available(LyXFont const & f) { if (!lyx_gui::use_gui) Index: FontLoader.h =================================================================== --- FontLoader.h (revision 15203) +++ FontLoader.h (working copy) @@ -18,14 +18,6 @@ #include <QFont> #include <QFontMetrics> -//#if QT_VERSION < 0x030100 -#define USE_LYX_FONTCACHE -//#endif - -#if defined(USE_LYX_FONTCACHE) -#include <map> -#endif - /** * Qt font loader for LyX. Matches LyXFonts against * actual QFont instances, and also caches metrics. @@ -35,18 +27,12 @@ QLFontInfo(LyXFont const & f); /// Return pixel width for the given unicode char - int width(Uchar val); + int width(Uchar val) const { return metrics.width(QChar(val)); } /// The font instance QFont font; /// Metrics on the font QFontMetrics metrics; - -#if defined(USE_LYX_FONTCACHE) - typedef std::map<Uchar, int> WidthCache; - /// Cache of char widths - WidthCache widthcache; -#endif }; @@ -55,9 +41,6 @@ public: /// FontLoader(); - - /// Destructor - ~FontLoader(); /// Update fonts after zoom, dpi, font names, or norm change void update();