Skip to content

[web] Improve performance of paragraphs with letter-spacing on canvas #51234

@mdebbar

Description

@mdebbar

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> elements

After 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 the maxLines property.

cc @ferhatb

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: typographyText rendering, possibly libtxtc: performanceRelates to speed or footprint issues (see "perf:" labels)engineflutter/engine related. See also e: labels.frameworkflutter/packages/flutter repository. See also f: labels.perf: speedPerformance issues related to (mostly rendering) speedplatform-webWeb applications specificallyteam-webOwned by Web platform teamtriaged-webTriaged by Web platform team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions