dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.28k stars 1.76k forks source link

[regression/8.0.0] Shadow performance has dropped precipitously in Windows, rendering previously in .NET 7 easily at 30+ FPS (frames per second), now as low as 1 FPS #18205

Open jonmdev opened 1 year ago

jonmdev commented 1 year ago

Description

Previously in .NET 7 Windows Shadow rendering speed was normal allowing normal layout speed and project frame rates of 30+ FPS during even debugging.

Now in .NET 8 the speed has dropped by over an order of magnitude and we are getting FPS rates of 1-20 for the same projects.

I do not know if this is related to the same performance problems happening with Android in both .NET 7 & .NET 8 as posted here:

https://github.com/dotnet/maui/issues/18202

However, the fact that Windows did not show this problem in .NET 7 but now shows it in .NET 8 clearly indicates this is some sort of Maui implementation problem and not a weakness of any inherent platform.

It also suggests that if it worked fine in .NET 7 in Windows, then got broken in .NET 8, this can be reversed and likely fixed in Android too.

My Windows desktop has a very strong consumer processor and at least a moderately strong graphics card, and yet it drops down to 1 FPS drawing this simple project. This makes no sense certainly. Same as my advanced 120 Hz Samsung device only rendering a simple project at 6 FPS. Neither makes sense.

BUG PROJECT This uses the same project as the linked report above. It just oscillates some Borders on screen in terms of their heights and debugs out the frame rate that it renders at. All custom code is in App.xaml.cs. All else is default Maui project.

This is what it looks like in Android (same in Windows): resize lag android 1 resize lag android 2resize lag android 3

Bonus Bug You can also see the abnormal Windows Shadow warping bug as reported here: https://github.com/dotnet/maui/issues/18172

The Shadow is not drawn correctly in .NET 7 or .NET 8 Windows as you can clearly see when playing this project. .NET 7 & .NET 8 have slightly different behavior as you can watch in this repro project but they are both very messed up.

Steps to Reproduce

Open project and press play. Look at debug output frame rate. Run in .NET 7 and see it is reasonable. Run in .NET 8 and see it is quite poor.

Link to public reproduction project repository

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

Version with bug

7.0.96

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

7.0.96

Affected platforms

Windows

Affected platform versions

Windows 10

Did you find any workaround?

None.

Relevant log output

1) In .NET 7:

CURRENT FPS 32.4485690181063
CURRENT FPS 35.1741118536757
CURRENT FPS 32.86338690065398
CURRENT FPS 33.1394674487581
CURRENT FPS 39.007493339470514
CURRENT FPS 31.42243058785083
CURRENT FPS 31.075588260885777
CURRENT FPS 31.609758564664084
CURRENT FPS 31.35562927612394
CURRENT FPS 31.381015740717494
CURRENT FPS 31.541562316664667
CURRENT FPS 31.98546580433851
CURRENT FPS 65.66678048908618
CURRENT FPS 31.139842806073514
CURRENT FPS 31.82898920678976
CURRENT FPS 31.84469976817059
CURRENT FPS 31.28627252220543

2) In .NET 8:

CURRENT FPS 11.863339079143893
CURRENT FPS 22.52592170440134
CURRENT FPS 11.900440911335766
CURRENT FPS 19.266857537002
CURRENT FPS 10.084884472605923
CURRENT FPS 18.578899943334356
CURRENT FPS 8.672003996059441
CURRENT FPS 9.841609142461229
CURRENT FPS 8.343080832772957
CURRENT FPS 11.797196750108238
CURRENT FPS 6.354701653112088
CURRENT FPS 7.672418423011117
CURRENT FPS 7.557830630527136
CURRENT FPS 6.165786911637491
CURRENT FPS 7.184548048820441
CURRENT FPS 6.844908072884581
CURRENT FPS 6.426603051865257
CURRENT FPS 5.050762690420067
CURRENT FPS 6.028639655547645
CURRENT FPS 5.549574347647535
CURRENT FPS 5.116076092422937
CURRENT FPS 1.5638194726800738
jsuarezruiz commented 1 year ago

After debugging a little bit, we have indeed gone from an average of 182fps (for 30s), to 0.65fps, a drastic drop in performance. This is a regression, introduced at https://github.com/dotnet/maui/commit/3f417755ea47b82b7daec807e723ea2bf6fa597d#diff-61362aac9bd0efecc45f0aec6d7c8c6d55758504c003e1109e7b4da0940b bae8

Removing line 287 from WrapperView: dropShadow.Mask = await Child.GetAlphaMaskAsync(); restore the previous performance.

issue-18205

Working on a fix for Issue 16094 but without impacting performance.

jonmdev commented 1 year ago

Glad to hear it was a simple fix @jsuarezruiz ! Since you have been looking at this, any thoughts about the similarly poor performance in Android with Shadow resizing?

It is equally crippling down to just 3-8 fps or so in Android (both .NET 7/8) even on strong devices that can handle high end 3D graphics and should certainly be able to draw some simple shadows.

https://github.com/dotnet/maui/issues/18202

Perhaps harder since it's broken in both versions so maybe less clear where the issue is coming from? Thanks for any thoughts.

jblank771 commented 5 months ago

When will the pull request that fixes this issue will be pulled into the main branch? Is there a service/maitenance milestone that has planned pulling this request?