[Development] Something is wrong in QFontEngineFT::loadGlyph

jiang.jiang at nokia.com jiang.jiang at nokia.com
Tue Feb 14 16:03:08 CET 2012

Hi Mark,

On Feb 14, 2012, at 12:03 AM, ext Mark wrote:
> While using Qt's elidedText function http://developer.qt.nokia.com/doc/qt-4.8/qfontmetricsf.html#elidedText i noticed the function was dog slow. For just 1000 entries (each 250 chars) eliding them to 200px took about 190ms on windows and 100ms on linux. Using that for drawing is noticeable slow. I haven't actually tried that, but i certainly would notice that and in the longer run that is my intention.
> So, i started playing with it in an attempt to get it blazing fast. And i got there. On windows i have a speedup of 39x (same job only takes 5ms) and on Linux i got a speedup of 10x (same job takes 10ms, side effect is that linux while 10x faster is now slower then windows.. odd), Those speedups are nice but it tasted like more so i went on to profilling. I already knew the QFontMetricsF::width was the function dragging everything down and a kcachegrind seems to indicate the same.
> Note for the speedups, i got them mostly by cashing the width of the used character thus avoiding the width function as much as possible.
> This is the path that width() takes till the point of calling the freetype functions:
> QFontEngineFT::stringToCMap
> QFontEngineFT::recalcAdvances
> QFontEngineFT::loadGlyph
> loadGlyph is where i think something odd is going on.
> http://qt.gitorious.org/qt/qt/blobs/4.8/src/gui/text/qfontengine_ft.cpp#line812
> Note the last parameter: "fetchMetricsOnly" ... The path it took had fetchMetricsOnly set to true : http://qt.gitorious.org/qt/qt/blobs/4.8/src/gui/text/qfontengine_ft.cpp#line1611. That leads me to think that this function is only going to fetch the metrics of the glyph, not render it! The opposite is the case. It's rendering it and that is the part that takes long.
> So, am i right here? Is this function doing to much? Remember, we come from the "width()" function. All we actually need is the width of the glyph, that's it.
> Actually, if you look in that function for the fetchMetricsOnly occurrence you'll see that it's only used in one place and there it doesn't seem to do a lot with metrics. It kinda looks like the original implementer of this has some idea, but never finished implementing it. Or am i wrong here?

Your guess is mostly correct. This fetchMetricsOnly flag was added a while ago (Nov 5, 2008) to suppress a warning message but it's actually useful to avoid doing rendering in that case. I think we should change (set->outline_drawing && fetchMetricsOnly) to (set->outline_drawing || fetchMetricsOnly) if not regression is caused. How is that working for you?

- Jiang

More information about the Development mailing list