Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve line wrapping performance #101725

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MewPurPur
Copy link
Contributor

@MewPurPur MewPurPur commented Jan 17, 2025

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:

  • 64 B -> 0.01ms
  • 350 B -> 0.03ms
  • 1.5 kB -> 0.15ms
  • 9 kB -> 3ms
  • 62 kB -> 65ms

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?

@fire fire added the bug label Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants