Skip to content
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

Improve AsyncImage performance. #1048

Merged
merged 143 commits into from
Jan 28, 2022
Merged

Conversation

colinrtwhite
Copy link
Member

@colinrtwhite colinrtwhite commented Dec 19, 2021

This PR focuses on improving AsyncImage's performance through the following changes:

  • AsyncImage now always uses Layout and never uses subcomposition. As a result, this PR moves AsyncImage's loading/success/error/content composable arguments into a new composable, SubcomposeAsyncImage.
  • Add painter arguments for placeholder/error/fallback and callbacks for onLoading/onSuccess/onError. Hopefully these arguments help users avoid using loading/success/error/content.
    • Also add overloads which accept transform and onState arguments. These are more flexible ways to override the Painter for a specific state and be notified about state changes.
    • These arguments don't restart the request if changed. I'm unsure if they should.
  • Remove the State argument from the content composable function so users aren't automatically opted into recomposing when the painter's state changes.
  • Remove code that was observing AsyncImagePainter.state inside AsyncImagePainter.kt.

There's a coil-sample-compose app in this repo that can be run to test out the improved scrolling performance.

EDIT: Updated to reflect the newest changes as of 26/01/2022.

@colinrtwhite colinrtwhite merged commit 06d56c9 into main Jan 28, 2022
@colinrtwhite colinrtwhite deleted the colin/async_image_performance branch January 28, 2022 21:34
colinrtwhite added a commit that referenced this pull request Oct 5, 2022
* Start optimizing.

* Refactor.

* Slight tweak.

* Docs.

* Docs.

* Don't observe AsyncImagePainter.state.

* Docs.

* Re-arrange.

* Remove parent scope.

* Clean up.

* Propagate min constraints for box.

* Manually invoke RememberObserver callbacks.

* Create a fake transition target.

* Remove import.

* Slight fix.

* Combine.

* Docs.

* Fix logic.

* Naming.

* Fix.

* Fix crossfade.

* Fix preview.

* Docs.

* Don't depend on state by default in content.

* Docs.

* Fix.

* Remove minor optimization.

* Use custom layout implementation.

* Docs.

* Refactor.

* Tweak.

* Tweak.

* Tweak.

* Move back.

* Add a custom content size modifier.

* Tweak.

* Docs.

* Docs.

* Add initial custom content painter modifier.

* Tweak.

* Tweak.

* Tweak.

* Refactor.

* Simplify.

* Fixes.

* Fix.

* Fix.

* Docs.

* Rename.

* Tweak.

* Tweak.

* Minor fixes.

* Make default cases faster.

* Docs.

* Support setting placeholder/error/fallback placeholders.

* Docs.

* Tweak.

* Docs.

* Docs.

* Tweak.

* Docs.

* Guard against infinite sizes.

* Rename.

* Prefix.

* Revert.

* Match behaviour.

* Docs.

* Docs.

* Rename.

* Add loading/success/error callbacks to AsyncImage.

* Tweak sample.

* Fix keys.

* Remove request from callbacks.

* Clean up.

* Use DefaultAlpha.

* Refactor.

* Refactor.

* Refactor.

* Docs.

* Revert.

* Add tests.

* Fix preview.

* Tweak.

* Rename.

* Add error painter.

* Fix tests.

* Tweak.

* Docs.

* Fix missing modifiers.

* Add tests for recomposition.

* Fix paths.

* Refactor.

* Use getAndIncrement.

* Validate.

* Validate.

* Fix tests.

* Performance tweak.

* Tweak.

* Docs.

* Add more tests.

* Tweak.

* Fix duplicate.

* Tweak.

* Fix crossfade.

* Docs.

* Refactor.

* Docs.

* Docs.

* Docs.

* Docs.

* Docs.

* Docs.

* Docs.

* Re-arrange.

* WIP.

* Rename to interceptor.

* Docs.

* Tweak.

* Docs.

* Rename.

* Tweak API.

* Update API.

* Fix tests.

* Rename parameter.

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

Successfully merging this pull request may close these issues.

1 participant