fix: improve large-document scroll performance - #107
Conversation
|
I'll review and merge it soon 👍 |
|
@zundaren Now, the lineWrap=true is smooth even in large files (tested on a 150k line code, as in the picture below), but the syntax highlighting is not working.
|
I'll adjust the highlighting effect and then test it. I have only tested 4 languages so far and haven't conducted extensive testing. |
|
@zundaren When typing on a line, the colour of that line flickers. And if lineWrap=true, on pressing backspace or Enter, the whole syntax highlight flickers. Screencast.from.2026-08-29.11-12-32.webm |
The core corrections are as follows:
The approach I took was:
The core corrections are as follows: 1.Latest submission, The input test did not observe any flickering.
The approach I took was:
|
|
I'll review it soon, I was very busy. |


Syntax highlighting is removed from the rendered frame.
Previously, when scrolling to the uncached area,
paint()would synchronously callre_highlight. Now, the first frame is drawn as regular text first, and then highlighted in the isolate background; as a result, only the color of this area is redrawn upon returning.Line height establishment for line breaks is queryable
After a line break, each line height is different. The original implementation continuously accumulates from the 0th line, and locating the 6000th line is O(n). Now, the average height of the sampled area is used as an estimate for the unknown line, and the actual measured height is used as an increment, placed in the Fenwick tree; by binary search/prefix sum O(log n), the first visible line is found.
Gutter must also reuse the same index
After optimizing the main text area, the gutter still scans from the first line once, causing line breaks to still be laggy. It is also changed to use the height index.
Features are classified by cost
Collapsing and indentation lines are not basic text rendering. The folding range of JSON parentheses may scan to the end of the document, and fast scrolling will trigger synchronous calculation. Therefore, JSON tools should first disable these two features; if they need to be retained later, they should be changed to background, lazy-loaded folding range.
Independent performance page verification:
flutter run -t lib/scroll_performance_main.dart