Details
-
Bug
-
Resolution: Done
-
P1: Critical
-
5.5.0, 5.5.1
-
None
-
Gentoo Linux ~x86_64
-
6f423555eba55ccdf7287071e10576bc1b687fd2
Description
Any Qt app with complicated text rendering (like KDE5 Konsole) has high CPU usage on text redrawing, original issue: https://bugs.kde.org/show_bug.cgi?id=354082 (and the gentoo one: https://bugs.gentoo.org/show_bug.cgi?id=564666)
How to reproduce:
- Open Konsole, run midnight commander (or any other curses-based app)
- Do any activity causing screen redraw (like changing folders)
- Konsole will become slow, unresponsive and use 100% CPU while redrawing. Downgrading Qt to 5.4 makes this issue disappear.
After a small research in callgrind, I've found the strange behaviour:
- On Qt5.5 FT_Load_Glyph is called 55000 times per minute (and growing with time), re-rendering every glyph every time it was shown.
- On Qt5.4 FT_Lload_Glyph is called 100-200 times per whole run, possibly rendering each glyph only once.
There is a QFontEngineFT::QGlyphSet cache to actually cache already rendered glyphs, and it used inside QFontEngine::loadGlyph. It caches glyphs based on their indexes, but loadGlyph will anyway re-render glyph if the cached glyph has different format. The problem is that:
- in Qt5.4 loadGlyph was called only once per glyph with format = A32, the caching worked fine.
- in Qt5.5 loadGlyph called twice per glyph with glyph (A32) and mask (A8). In that case the cache was constantly updated with glyphs with different formats, loadGlyph was contantly re-rendering glyphs because of the format mismatch.