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

Android shadow performance #26789

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

albyrock87
Copy link
Contributor

@albyrock87 albyrock87 commented Dec 23, 2024

Description of Change

Apparently DrawShadow has an absurd impact on the performance.
Here's a speedscope from our app sorted by self time descending, also look at total time %!!!
image

This PR:

  • moves the shadow computation to android level to avoid back and forth from C#
  • uses Glide's LruBitmapPool to reduce the memory pressure on Java
  • fixes shadow rendering on Android which was still broken (despite Shadows not rendering as expected on Android and iOS #24414) under some conditions (like negative offsets)

I tried as much as possible to not break signatures but given Java to C# bindings are automatically generated, there was no way completely avoid touching public APIs.

Here I've executed the testing host app with return new ShadowBenchmark(); as main page and scrolling the CV for ~30 seconds.

Before

DrawShadow takes 24%.

image
before.speedscope.json

image

After

DrawShadow is gone.

image
after.speedscope.json

image

Issues Fixed

@albyrock87 albyrock87 requested a review from a team as a code owner December 23, 2024 16:46
@albyrock87 albyrock87 marked this pull request as draft December 23, 2024 16:46
@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Dec 23, 2024
@PureWeen
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen PureWeen added this to the .NET 9 SR4 milestone Dec 23, 2024
@PureWeen
Copy link
Member

/rebase

@PureWeen
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@albyrock87 albyrock87 force-pushed the android-shadow branch 5 times, most recently from 2f0b86f to eccf37e Compare December 24, 2024 13:45
@AmrAlSayed0
Copy link
Contributor

I'm late to the party but an attempt to improve shadow's performance was made before here #10523. Moving the code to the Java side might help but I think what would benefit the most is a shadow cache. All views that have the same size and the same shadow properties (very common scenario in CollectionView items for example) should use the same bitmap. This will eliminate a huge number of calls including C# to Java ones. There is an implementation of the shadow cache in the PR.

@albyrock87
Copy link
Contributor Author

@AmrAlSayed0 thanks for sharing, I'll check it out.
This is still a very early WIP.
I also intend using Glide's bitmap pool for this, which should improve the performance by avoiding continuous allocations of the bitmaps.

@albyrock87 albyrock87 force-pushed the android-shadow branch 6 times, most recently from d1ead23 to a7e91b9 Compare December 24, 2024 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community ✨ Community Contribution
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

3 participants