Skip to content

[android] avoid View.Context during CollectionView scrolling#8243

Merged
hartez merged 1 commit intodotnet:mainfrom
jonathanpeppers:CollectionViewContext
Jun 22, 2022
Merged

[android] avoid View.Context during CollectionView scrolling#8243
hartez merged 1 commit intodotnet:mainfrom
jonathanpeppers:CollectionViewContext

Conversation

@jonathanpeppers
Copy link
Member

Context: #8012
Context: https://github.com/Kalyxt/Test_CollectionView

We had some reports of poor CollectionView performance while
scrolling on an older Android device.

Reviewing dotnet trace output, I did find some issues similar to #8001:

317.42ms (1.1%) mono.android!Android.Views.View.get_Context()

image

1% of the time is spent in repeated calls to View.Context inside the
ItemContentView class. Making a new overload for
ContextExtensions.FromPixel(), I was able to remove all of these
calls.

This results in only a couple View.Context calls on startup now,
much better:

1.30ms (0.01%) mono.android!Android.Views.View.get_Context()

Using the "janky frames" metric from the latest profiler in Android
Studio Dolphin:

https://developer.android.com/studio/profile/jank-detection

With my slowest Android 12+ device, a Pixel 4a, I could actually see a
few "janky frames" while scrolling the sample.

image

With these changes in place, I only see 1 "janky frame" now:

image

I also compared the before and after with the visual GPU profiler:

https://developer.android.com/topic/performance/rendering/inspect-gpu-rendering

Before:

image

After:

image

It appears at a glance that these changes are better.

I am unsure at what point the performance will be good enough to close
#8012, but this helps!

Context: dotnet#8012
Context: https://github.com/Kalyxt/Test_CollectionView

We had some reports of poor `CollectionView` performance while
scrolling on an older Android device.

Reviewing `dotnet trace` output, I did find some issues similar to dotnet#8001:

    317.42ms (1.1%) mono.android!Android.Views.View.get_Context()

1% of the time is spent in repeated calls to `View.Context` inside the
`ItemContentView` class. Making a new overload for
`ContextExtensions.FromPixel()`, I was able to remove all of these
calls.

This results in only a couple `View.Context` calls on startup now,
much better:

    1.30ms (0.01%) mono.android!Android.Views.View.get_Context()

Using the "janky frames" metric from the latest profiler in Android
Studio Dolphin:

https://developer.android.com/studio/profile/jank-detection

With my slowest Android 12+ device, a Pixel 4a, I could actually see a
few "janky frames" while scrolling the sample.

With these changes in place, I only see 1 "janky frame" now.

I also compared the before and after with the visual GPU profiler:

https://developer.android.com/topic/performance/rendering/inspect-gpu-rendering

It appears at a glance that these changes are better.

I am unsure at what point the performance will be good enough to close
 dotnet#8012, but this helps!
@jonathanpeppers jonathanpeppers changed the title [android] avoid View.Context during ContextView scrolling [android] avoid View.Context during CollectionView scrolling Jun 22, 2022
@Eilon Eilon added the legacy-area-perf Startup / Runtime performance label Jun 22, 2022
@hartez hartez merged commit eea91d3 into dotnet:main Jun 22, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Dec 20, 2023
@Eilon Eilon added the perf/general The issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf) label May 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

fixed-in-7.0.0-rc.1.6683 legacy-area-perf Startup / Runtime performance perf/general The issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf)

Projects

No open projects
Status: Done & Blogged

Development

Successfully merging this pull request may close these issues.

4 participants