Created attachment 179882 [details] file in question SUMMARY Kate becomes very slows and hogs CPU on attached file. STEPS TO REPRODUCE 1. Open attached file 2. Select any text Cpu goes to close to 100%. I noticed that kate uses UTF-8 mode, and makes it readonly when trying utf-7. But there are no UTF-8 characters AFAIK SOFTWARE/OS VERSIONS Operating System: Ubuntu 12 (not sure why it says that! It is on Ubunut 25.04 devel) KDE Plasma Version: 6.3.3 KDE Frameworks Version: 6.12.0 Qt Version: 6.8.2 Kernel Version: 6.14.0-11-generic (64-bit) Graphics Platform: X11 Processors: 12 × 13th Gen Intel® Core™ i5-1335U Memory: 31.0 GiB of RAM Graphics Processor: Intel® Iris® Xe Graphics
The slowdown is in Qt. Its unable to handle a large number of format ranges that are produced by KateRenderer::decorationsForLine when the ranges are passed to QTextLayout::draw(). During text layouting this is not an issue. One possible fix could be to render selection ourselves always: - remove the following check in decorationsForLine so that we use the correct foreground color during layouting. This will have implications for printing and screenshot so that needs to be kept in mind: if (selectionsOnly) { assignSelectionBrushesFromAttribute(fr, *a); } - Dont use Qt for selection background. Use our own function paintTextBackground, that function needs a bit more testing, I think its still a little bit broken with multiple wrapped lines On quick testing, this removes all lag.
(In reply to Waqar Ahmed from comment #1) > The slowdown is in Qt. Its unable to handle a large number of format ranges > that are produced by KateRenderer::decorationsForLine when the ranges are > passed to QTextLayout::draw(). During text layouting this is not an issue. > > One possible fix could be to render selection ourselves always: > - remove the following check in decorationsForLine so that we use the > correct foreground color during layouting. This will have implications for > printing and screenshot so that needs to be kept in mind: > if (selectionsOnly) { > assignSelectionBrushesFromAttribute(fr, *a); > } > - Dont use Qt for selection background. Use our own function > paintTextBackground, that function needs a bit more testing, I think its > still a little bit broken with multiple wrapped lines > > On quick testing, this removes all lag. Given we do most other painting ourself, too, that would be fine with me.
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/ktexteditor/-/merge_requests/815
Git commit 0cb99379131b6fb2b80637e6e86da428a630f3bf by Christoph Cullmann, on behalf of Waqar Ahmed. Committed on 12/06/2025 at 19:45. Pushed by cullmann into branch 'master'. Draw selection background ourselves We were using the "selectionFormats" parameter of QTextLayout::draw() to draw selections and supplied background + foreground formats for drawing selections. This leads to extremely poor performance when there are a lot of "selection formats" e.g., a large list of numbers on a single line. To fix this, draw the selection background ourselves and handle the foreground formats during text layouting phase. M +5 -22 src/render/katerenderer.cpp https://invent.kde.org/frameworks/ktexteditor/-/commit/0cb99379131b6fb2b80637e6e86da428a630f3bf