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 is poor #27156

Closed
albyrock87 opened this issue Jan 15, 2025 · 2 comments · Fixed by #26789
Closed

Android Shadow performance is poor #27156

albyrock87 opened this issue Jan 15, 2025 · 2 comments · Fixed by #26789
Labels
area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing platform/android 🤖 t/bug Something isn't working t/perf The issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf)
Milestone

Comments

@albyrock87
Copy link
Contributor

albyrock87 commented Jan 15, 2025

Description

The speedscope

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

Why is this happening?

This is what happened while drawing the Android.Views.View every time you enable a Shadow somewhere:

  1. It creates a shadow Bitmap in memory
  2. It draws the descendants on top of that Bitmap
  3. It creates another Bitmap to extract Alpha channel (extractAlpha)
  4. It clears the shadow Bitmap
  5. It draws the alpha bitmap to the shadow bitmap with blur and coloring
  6. Shadow bitmap is cached on a field to be reused on subsequent draw
  7. It draws the shadow bitmap to the rendering pipeline canvas
  8. It draws the descendants once again, but this time on the rendering pipeline canvas

You can imagine the kind of slow down this generates when a shadow is applied to a node which has a lot of descendants.
The cache at field level is really a poor one, in the sense that invalidation happens every time something changes on the descendants via requestLayout.

Steps to Reproduce

Use a real-world application containing shadows, profile it, and see how drawShadows consumes a lot of CPU.

Link to public reproduction project repository

No response

Version with bug

9.0.30 SR3

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

No workaround available besides not using shadows.

@albyrock87 albyrock87 added the t/bug Something isn't working label Jan 15, 2025
@StephaneDelcroix StephaneDelcroix added platform/android 🤖 area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing labels Jan 16, 2025
@StephaneDelcroix
Copy link
Contributor

/cc @jonathanpeppers

@StephaneDelcroix StephaneDelcroix added the t/perf The issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf) label Jan 16, 2025
@StephaneDelcroix StephaneDelcroix added this to the Backlog milestone Jan 16, 2025
@jonathanpeppers
Copy link
Member

Android has always been slow (literally for decade+) as soon as:

  • You use Android.Graphics.Bitmap: C# GC doesn't know the true size of these, and so OOM can result.
  • You use Android.Graphics.Canvas: if I remember correctly, is never hardware accelerated.

So, if there is a way to implement shadow with Drawable instead, that will perform much better.

@PureWeen PureWeen modified the milestones: Backlog, .NET 9 SR4 Jan 16, 2025
@PureWeen PureWeen moved this from Todo to In Progress in MAUI SDK Ongoing Jan 28, 2025
@github-project-automation github-project-automation bot moved this from In Progress to Done in MAUI SDK Ongoing Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing platform/android 🤖 t/bug Something isn't working t/perf The issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf)
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants