QTextLayout::draw does not take into account QPainter's viewport, so it will try to render lines outside visible bounds. This causes a significant slowdown when a very long line is dynamically broken into multiple lines. To avoid this, an explicit text clip rect is set.
To avoid making assumptions on the world transform of the painter (it could be sheared or rotated, after all), an explicit clip rect is used instead of guessing whether the resulting line would end up outside the screen or not.
$ kwrite /var/log/apt/history.log.1.gz
The longest of those lines was 75.394 characters long
[Temporarily raise limit and reload file]
No longer causes a massive slowdown when scrolling the file with dynamic word wrap enabled.
Quite crude but definitely worth it from performance POV. Wonder if Qt could be optimized there somehow.
QPainter probably drops all the calls
QTextLayout makes outside the visible area but it still incurs some processing.