Improve line wrapping performance #101725
Draft
+16
−9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While this PR's implementation works, it's more so meant to start a discussion than to actually be finished. I think there are probably better ways to go about this.
In a nutshell, very long lines are really harsh on TextEdit when wrapping is enabled. I made this benchmark in 4.4.beta1 for
get_rect_at_line_column()
, an example of a method that's bottlenecked by this:Not a very tight benchmark, as the amount of linewraps matters more (it's roughly every 50 characters for the benchmark) but it shows how the method gets slower way too fast. 62 kB is 180 times more than 350 B, but it's 2200 times slower.
In development builds, with the 9 kB line, I got 7.8ms; with this PR, I get 0.8ms and I don't notice any regressions.
If I gauge correctly, the issue is that
_shape_lines()
in TextParagraph is called numerous times without anything that would actually change the output. Wouldn't caching make more sense then, and be implemented throughout the class?