Skip to content

feat(mobile): optimized thumbnail rendering #19822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

mertalev
Copy link
Member

@mertalev mertalev commented Jul 8, 2025

Description

Uses custom optimized image widgets along with a better thumbnail preparation process to make thumbnails render significantly more quickly than before, and in significantly higher quality.

Later PRs can improve this further using in-memory image caching and canceling image requests for offscreen widgets.

Notably, I also tested a platform view-based implementation based on UIImage. However, the high number of platform views made scrolling stutter-y and used more memory, so transferring the image to Flutter's rendering engine is more efficient. I want to try this approach for the asset viewer in a later PR though.

To do:

  • Android implementation
  • Support contain vs cover fit
  • Code cleanup
  • Test pages and in different conditions (fast vs slow device, fast vs slow internet, etc.)

How Has This Been Tested?

Tested by scrolling and scrubbing in the timeline.

Comment on lines -61 to -65
: FadeInPlaceholderImage(
placeholder: const ThumbnailPlaceholder(),
image: ThumbHashProvider(thumbHash: thumbHash),
fit: fit ?? BoxFit.cover,
);
Copy link
Member

Choose a reason for hiding this comment

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

The reason we did it this way was to prevent the flashing when the widget changes from the placeholder to the thumbhash. Can you try wrapping them around with AnimatedSwitcher to make the transition a bit smooth?

Copy link
Member Author

@mertalev mertalev Jul 9, 2025

Choose a reason for hiding this comment

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

The thumbhash is the placeholder, I don't see why you'd want to delay displaying it. You want it to show as quickly as possible because the thumbnail is going to display soon. Also having less complex rendering stuff in here is good for scrolling performance.

Copy link
Member

@alextran1502 alextran1502 Jul 9, 2025

Choose a reason for hiding this comment

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

The changes in this PR make thumbhash loading feel abrupt. If you are not scrubbing but scrolling really fast, you will see many assets' state indicators floating on the screen instead of sitting on top of a defined placeholder area

On main I think the sequence is

Placeholder > Thumbhash > Image

In this PR, the sequence is

Blank > Thumbhash > Image

I think if we want to achieve a nicer feeling, it must be

Thumbhash > Image

Copy link
Member Author

Choose a reason for hiding this comment

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

Did you test with a release build? I generally see the thumbhash straight away even when scrolling quickly. I haven't seen a blank screen with indicators like you describe. Also, I usually don't get to see the thumbhash on main because it's too slow to come in, so it's more like placeholder -> thumbnail.

Copy link
Member

Choose a reason for hiding this comment

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

Yes I test with the release build on Android, connecting to the main preview instance

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, I guess it's a timing difference since I'm on iOS. Let me try to reproduce this.

@alextran1502
Copy link
Member

Hi Mert, do you have any changes that you want to push for testing?

@mertalev mertalev force-pushed the refactor/mobile-thumbhash branch from c482bdf to dbf9712 Compare July 18, 2025 11:41
@mertalev mertalev changed the title refactor(mobile): thumbhashes feat(mobile): optimized thumbnail rendering Jul 18, 2025
@mertalev mertalev marked this pull request as draft July 18, 2025 11:42
@mertalev
Copy link
Member Author

Hi Mert, do you have any changes that you want to push for testing?

I pushed my thumbnail optimizations so you can give it a try. It's very much WIP (only iOS is implemented), but the results should speak for themselves.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants