[web] Improve performance of paragraphs with letter-spacing on canvas #51234
Labels
a: typography
Text rendering, possibly libtxt
c: performance
Relates to speed or footprint issues (see "perf:" labels)
engine
flutter/engine repository. See also e: labels.
framework
flutter/packages/flutter repository. See also f: labels.
P2
Important issues not at the top of the work list
perf: speed
Performance issues related to (mostly rendering) speed
platform-web
Web applications specifically
team-web
Owned by Web platform team
triaged-web
Triaged by Web platform team
Projects
Problem
When rendering a paragraph that has letter-spacing on canvas, we do it inefficiently. Basically, we render each letter, measure it, render the next letter, measure it, etc. We do this because canvas doesn't support letter-spacing, so we have to figure out the position of each letter ourselves. The relevant code is here.
This is causing a significant performance hit in some apps that heavily use letter-spacing. We need a better way to do this.
Solutions
1. Fallback to DOM rendering
One fix would be to simply fallback to DOM rendering (the whole paragraph in a
<p>
element) when the paragraph has letter-spacing. But this means we will inherit the other issues that come with DOM rendering, namely the handling of ellipsis isn't 100% correct.2. Split lines into
<span>
elementsAfter the layout and measurements are done by canvas, we could use the
LineMetrics
information to render each line individually in a<span>
or even a<p>
element. This way we can still put the ellipsis in the correct line, and fully respect themaxLines
property.cc @ferhatb
The text was updated successfully, but these errors were encountered: