Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@yjbanov
Copy link
Contributor

@yjbanov yjbanov commented May 26, 2021

Put CkParagraph objects into a separate synchronous cache, which reclaims memory synchronously. This significantly reduces paragraph memory usage for very long ListViews and other cases where lots of paragraphs are laid out but not rendered. It does not fully cover the use-case where we both lay out and render tons of paragraphs (it fixes the memory issue but not the performance issue). For that we need flutter/flutter#81224.

Some benchmark numbers:

text_canvas_kit_color_grid: before 420MB, after 153MB
Layout and render 10000 paragraphs: before 1GB, after 200MB
sample 1, 60 seconds (by @slavap): before 600MB, after 168MB
sample 2, 100 tab switches (by @asjqkkkk): before 422MB, after 253MB

Fixes flutter/flutter#66614

@yjbanov yjbanov requested a review from harryterkelsen May 26, 2021 18:39
@flutter-dashboard flutter-dashboard bot added the platform-web Code specifically for the web engine label May 26, 2021
@google-cla google-cla bot added the cla: yes label May 26, 2021
Copy link
Contributor

@harryterkelsen harryterkelsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach seems good to me

/// blowing up if within a single frame the framework needs to layout a lot of
/// paragraphs. One common use-case is `ListView.builder`, which needs to layout
/// more of its content than it actually renders to compute the scroll position.
void release() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this name is a little confusing. release makes me think we are telling the cache to delete this paragraph ASAP. I think something like addToCache or markUsed would make more sense

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Done.

Copy link
Contributor

@harryterkelsen harryterkelsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes platform-web Code specifically for the web engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CanvasKit uses too much memory (~100KB) per laid out paragraph

2 participants