Skip to content

Shadows are incredibly slow to draw in Android, dropping app performance to 6 FPS (frames per second) #18202

@jonmdev

Description

@jonmdev

Description

Currently any objects that use Shadows cannot be resized in any reasonable fashion in Android Maui. Even on a high end flagship Samsung 120 Hz device, performance drops to 6-8 fps just trying to redraw a few Border elements on screen with Shadows.

This is certainly not normal or expected behavior. I wonder if it is trying to draw these on the CPU rather than GPU? I am not sure what it could be. I don't know enough about graphics rendering unfortunately.

DEMO PROJECT
My repro project places 4 Borders on the screen and then animates 3 of the Borders with Shadows at a given approximate FPS based on a timer. It is set to 50 fps by default. It is expected this should result in around a 45-48 fps project as Timers may lag a bit based on scheduling.

There is a simple int for the approximate target FPS and bool for adding shadows or not. In Android, a listener is added to the layout event so you can track the exact frames per second on debug output.

It animates 3 purple Border elements with Shadows from small to big and back in an oscillation.

All project code is in App.xaml.cs. The rest is default Maui project.

resize lag android 1 resize lag android 2 resize lag android 3

RESULTS:
You will see on the debug output even with using a high end 120 Hz advanced CPU/GPU flagship top of the line Samsung test Android device, frame rate drops to 6-8 frames per second when the Border elements reach their peak size.

At best, even when they are small we can attain around 30 fps, which is also pretty abysmal and suggests something is wrong.

On Pixel 5 emulator, frame rate drops as low as 3 FPS with Shadows.

I wonder if this is related to this bug though I don't know: #17881

It seems the Shadows are not being drawn in any reasonable or efficient manner.

Steps to Reproduce

  1. Open project, press play with virtual or physical Android device attached.
  2. See frame rate output which ranges 6-30 FPS at best with Shadows, but can hit the expected 45-48 FPS or so with no trouble without them.
  3. On Pixel 5 emulator, frame rate will drop as low as 3 FPS.

Link to public reproduction project repository

https://github.com/jonmdev/Resize-Lag-Bug

Version with bug

.NET 7 & .NET 8

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Unknown/Other

Affected platforms

Android

Did you find any workaround?

Don't use Shadows on Android? Or expect to resize or animate anything that does? Not really great.

Relevant log output

Using high end Android physical device for testing, results are as follows.

1) OUTPUT WITH SHADOWS, TARGETING ~50 FPS:

//=================================
//WHEN SHADOW OBJECTS ARE SMALL
//=================================
[0:] CURRENT FPS 28.842548527587898
[0:] CURRENT FPS 25.603801652469357
[0:] CURRENT FPS 28.190613653278007
[0:] CURRENT FPS 31.757424091817064
[0:] CURRENT FPS 23.399694867978923
[0:] CURRENT FPS 31.193948374015438
[0:] CURRENT FPS 33.59594161025348
[0:] CURRENT FPS 23.0427489077737
[0:] CURRENT FPS 26.84340363620746
[0:] CURRENT FPS 23.07656805279919
[0:] CURRENT FPS 28.753975237076528
[0:] CURRENT FPS 27.488688404721458
[0:] CURRENT FPS 26.46777019623205
[0:] CURRENT FPS 21.51092755119601
[0:] CURRENT FPS 24.395360978156397
[0:] CURRENT FPS 20.434102064252993
[0:] CURRENT FPS 20.28751465772934
[0:] CURRENT FPS 16.020942576135525
[0:] CURRENT FPS 25.857365599877955
[0:] CURRENT FPS 20.26954440145049
[0:] CURRENT FPS 20.408954632934744
[0:] CURRENT FPS 20.928032681215836
[0:] CURRENT FPS 21.0176758654028
[0:] CURRENT FPS 21.123919247481503
[0:] CURRENT FPS 20.737207734978483
[0:] CURRENT FPS 17.50945510575711
[0:] CURRENT FPS 15.975589299550288
[0:] CURRENT FPS 14.855838938936559
[0:] CURRENT FPS 12.73685779170907
[0:] CURRENT FPS 14.092923097737241
[0:] CURRENT FPS 13.749805783993303
[0:] CURRENT FPS 10.186847150433247
[0:] CURRENT FPS 12.006906372545489
[0:] CURRENT FPS 11.683293941160596
[0:] CURRENT FPS 10.110978095577053
[0:] CURRENT FPS 9.37268611811459
[0:] CURRENT FPS 8.421407217145985
[0:] CURRENT FPS 9.367979870084856
[0:] CURRENT FPS 7.802734390239715
[0:] CURRENT FPS 7.019016621733263
[0:] CURRENT FPS 8.172859242114416
[0:] CURRENT FPS 6.795394081891295
[0:] CURRENT FPS 6.781054006348422
[0:] CURRENT FPS 6.521668242736492
[0:] CURRENT FPS 6.443328030474364
[0:] CURRENT FPS 6.317574354691367
[0:] CURRENT FPS 6.067059205397255
[0:] CURRENT FPS 6.112454492776301
//=================================
//WHEN SHADOW OBJECTS ARE LARGE
//=================================

2) OUTPUT WITHOUT SHADOWS, TARGETING ~50 FPS (CONSISTENT EXPECTED RESULT)

[0:] CURRENT FPS 48.131302192380815
[0:] CURRENT FPS 43.59121898484769
[0:] CURRENT FPS 46.7525667159127
[0:] CURRENT FPS 46.17039646519445
[0:] CURRENT FPS 44.36025853158672
[0:] CURRENT FPS 44.971106064353656
[0:] CURRENT FPS 45.243750706933604
[0:] CURRENT FPS 45.01361661902726
[0:] CURRENT FPS 43.967639817094614
[0:] CURRENT FPS 45.042001666554064
[0:] CURRENT FPS 45.38770174833427
[0:] CURRENT FPS 45.61357094962894
[0:] CURRENT FPS 44.74112783435045
[0:] CURRENT FPS 43.66621544910702
[0:] CURRENT FPS 45.7331016189518
[0:] CURRENT FPS 46.28493934358699

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-drawingShapes, Borders, Shadows, Graphics, BoxView, custom drawingdelighter-scperf/generalThe issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf)platform/androidt/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions