-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
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