Skip to content

[web: canvaskit] move from drawParagraph to drawGlyphs #81224

@yjbanov

Description

@yjbanov

Move CanvasKit from drawParagraph to drawGlyphs.

Relying on drawParagraph requires that we hold onto the laid out SkParagraph object. There are usage patterns that make it prohibitively expensive. For example, when an app has an extremely long scrollable area expressed using a ListView.builder with variable-height items and the user snaps the scrollbar to a position far into the list (in the worst case all that way to the bottom), the framework needs to layout all widgets that appear prior to the scroll position. In this situation most of the paragraphs will be laid out but never rendered. Keeping the layout information consumes enormous amounts of memory (100KB/paragraph, so a 10,000-item list would need 1GB of RAM). It should therefore be more optimal to "forget" the layout information about those paragraphs (some trivial information can be cached, such as width, height, baselines, intrinsic sizes) and only keep the rendering information (List<GlyphRun>), which is significantly sparser. Glyph runs are rendered using Canvas.drawGlyphs and doesn't require a paragraph object. An extra benefit is that GlyphRun is a 100% JS object and doesn't require any GC tricks, such as weak refs.

This requires an extra feature in CanvasKit: https://bugs.chromium.org/p/skia/issues/detail?id=11907

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)dependency: skiaSkia team may need to help use: web_canvaskitCanvasKit (a.k.a. Skia-on-WebGL) rendering backend for Webengineflutter/engine related. See also e: labels.f: scrollingViewports, list views, slivers, etc.perf: memoryPerformance issues related to memoryperf: speedPerformance issues related to (mostly rendering) speedplatform-webWeb applications specifically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions