Skip to content

[Android] Improve CollectionView scrolling (Shadows) - #10523

Closed
jsuarezruiz wants to merge 12 commits into
mainfrom
fix-9485
Closed

jsuarezruiz wants to merge 12 commits into
mainfrom
fix-9485

Conversation

@jsuarezruiz

@jsuarezruiz jsuarezruiz commented Oct 6, 2022 •

Copy link
Copy Markdown
Contributor

Description of Change

This PR include changes to:

  • Dispose (reset BindingContext, dispose etc) the internal ContentViews from CollectionView on Android.
  • Added a Shadow's Cache. With the sample from the issue, creating a list of 100 items after scroll to the end was creating new bitmaps (shadows) by every item. The drawing and memory penalty was high. With the cache included, and using the same sample, only 2 bitmaps are created, and are constantly reused.

With these changes, the scroll behavior passes from unusable to something much better, but jittering is still noticeable. We still MUST continue reviewing samples, debugging and improving to offer the best possible experience with the CollectionView.

To test the changes, navigate to the shadows gallery and select the benchmark page. Scroll the CollectionView for example until the item 50 and check in the Output that the shadow cache only contains 2 bitmaps.

image

NOTE: The gray color around the circular play button is a Shadow.

image

More changes related with CollectionView https://github.com/dotnet/maui/pull/10590/files

Issues Fixed

Fixes #9485

@jsuarezruiz jsuarezruiz added t/bug Something isn't working platform/android area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing legacy-area-perf Startup / Runtime performance area-controls-collectionview CollectionView, CarouselView, IndicatorView labels Oct 6, 2022
@jsuarezruiz
jsuarezruiz marked this pull request as ready for review October 13, 2022 11:04
@jsuarezruiz jsuarezruiz changed the title [Android] Improve CollectionView scrolling [Android] Improve CollectionView scrolling (Shadows) Oct 13, 2022
@jsuarezruiz
jsuarezruiz marked this pull request as draft November 3, 2022 08:52
@jsuarezruiz
jsuarezruiz marked this pull request as ready for review November 18, 2022 12:55
@hartez

hartez commented Dec 14, 2022

Copy link
Copy Markdown
Contributor

Dispose (reset BindingContext, dispose etc) the internal ContentViews from CollectionView on Android.

Do you have any data to show this improves scrolling speed? It doesn't seem like it would have any bearing on the scrolling, since it doesn't happen until the CollectionView is being disposed (or the ItemsSource changes).

The shadow caching portion may help with the scrolling speed, but I'm suspicious of the other changes. This should be two separate PRs so we can evaluate each one independently.


public Bitmap Add(string id, Func<Bitmap> create)
{
Debug.WriteLine($"Add {id}");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Left a debugging statement in there.

internal class ShadowCache : IDisposable
{
static ShadowCache _instance;
readonly Dictionary<string, BitmapReference> _cache;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rather than all this custom code, can this be done with a ConcurrentDictionary?

@jsuarezruiz
jsuarezruiz marked this pull request as draft December 15, 2022 10:07
@jsuarezruiz

Copy link
Copy Markdown
Contributor Author

Converted back to Draft. Rebasing and testing everything, something has changed in this time and it doesn't work as expected. I will review everything to know what changed.

@jsuarezruiz

Copy link
Copy Markdown
Contributor Author

The approach is good but we will reopen it with a different implementation.

@github-actions github-actions Bot locked and limited conversation to collaborators Dec 17, 2023
@Eilon Eilon added perf/general The issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf) and removed legacy-area-perf Startup / Runtime performance labels May 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-controls-collectionview CollectionView, CarouselView, IndicatorView area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing perf/general The issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf) platform/android t/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] Slow scrolling, laggy performance

4 participants