On Wed, Oct 04, 2006 at 11:05:16AM +0200, Abdelrazak Younes wrote: > Andre Poenitz wrote: > >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...]: > > ucs4_to_qstring is pretty simple: > > QString const ucs4_to_qstring(char_type const * str, size_t ls) > { > QString s; > > for (size_t i = 0; i < ls; ++i) > s.append(ucs4_to_qchar(str[i])); > > return s; > } > > So, maybe with a static QString we could speed up the thing.
Using QString at all is probably the problem. > But I thought that QString were implicitely shared... That's only part of the problem. The sharing involves atomic operations for bumping the reference counter which is about the best rat poison one can get for performance on multicore systems - but that doesn't hit us here as desktops most like don't have much more then two CPU cores nowadays. The main problem is the dynamic allocation of the QString data (and possible reallocations at append() time. Having that once per displayed char is pretty expensive. > And ucs4_to_qchar is a simple cast solution: > > QChar const ucs4_to_qchar(char_type const & ucs4) > { > return QChar(static_cast<unsigned short>(ucs4)); > } This is fine. QChar is cheap. > We could also use a static QChar here, dunno... > > >I will apply the patch tomorrow evening unless I get objections or > >somebody else is faster. > > Note that I already made some changes to Fontloader so you'll need to > adapt your patch. FYI the reason why the cache was re-enabled was > because of really bad performance under MacOSX. > But I am not formally opposed to the patch as I think that this is a bad > solution. We'll try to investigate other solution for MacOSX performance > problems. It could well be that the problem will disappear with Qt4.2, > dunno. If we need a cache solution on the Mac I'd rather use an array for the first, say, 256 chars, not a map. This has about the same performanc as the non-inlined version on X11, i.e. something like { private: int metriccache_[256] } c'tor: for (int i = 0; i != 256; ++i) metricscache_[i] = -1 ::metrics() if (c >= 256) return width(c) if (metricscache_[c] == -1) metricscache[c] = width(c); return metricscache[c]; Andre'