Skip to content

Fix LRUness of ScrollAwareImageProvider - #50242

Merged
dnfield merged 3 commits into
flutter:masterfrom
dnfield:lru_fix
Feb 6, 2020
Merged

dnfield merged 3 commits into
flutter:masterfrom
dnfield:lru_fix

Conversation

@dnfield

@dnfield dnfield commented Feb 6, 2020

Copy link
Copy Markdown
Contributor

Description

#49389 introduced a subtle bug where, if an image got precached while you are scrolling fast, the scrolling image provider would not update the ImageCache's LRU information. The test for this is very highly constructed to push this, as it would be very hard to do this in a real application. I actually discovered this while working through a solution for #49456, where this will become more important, but it's fixable by itself so I'm splitting it out.

Related Issues

The two linked bugs above.

Tests

I added the following tests:

A test that precaches an image while scrolling fast, and then observes that our image overwrites it in the cache (cache size = 1) once it completes, still while scrolling fast. This test is highly constructed, and would be very difficult to achieve in a real application without writing custom image providers.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

  • No, no existing tests failed, so this is not a breaking change.

@dnfield
dnfield requested a review from goderbauer February 6, 2020 01:56
@fluttergithubbot fluttergithubbot added the framework flutter/packages/flutter repository. See also f: labels. label Feb 6, 2020

@goderbauer goderbauer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

// the image we want before getting to this method. We should avoid calling
// load again, but still update the image cache with LRU information.
if (stream.completer != null) {
PaintingBinding.instance.imageCache.putIfAbsent(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe assert after this that it returned stream.completer as expected?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@dnfield

dnfield commented Feb 6, 2020

Copy link
Copy Markdown
Contributor Author

The tree is not red, manually checked - we're having issues with cocoon right now when it tries to check status. Landing.

@dnfield
dnfield merged commit d94ff4b into flutter:master Feb 6, 2020
@dnfield
dnfield deleted the lru_fix branch February 6, 2020 21:19
@dnfield dnfield added the a: images Loading, displaying, rendering images label Feb 18, 2020
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

a: images Loading, displaying, rendering images framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants