microsoft / microsoft-ui-xaml

WinUI: a modern UI framework with a rich set of controls and styles to build dynamic and high-performing Windows applications.
MIT License
6.38k stars 683 forks source link

UWP app launches very slow with many assets #2203

Open MartinZikmund opened 4 years ago

MartinZikmund commented 4 years ago

Describe the bug

UWP app launch length is proportional to the number of assets included in the project (e.g. images with Build Action set to Content). Even for a simple blank page, which does not do anything, just having many assets present in the application package causes the app to load extremely slow - while the code is not touching them at all.

Steps to reproduce the bug Steps to reproduce the behavior:

  1. Create a blank app
  2. Launch it - observe it starts up almost immediately
  3. Add 1000 small images in the Assets folder (even icons are enough)
  4. Launch app - it may now take even 20 seconds to launch

For better convenience, I have created a simple repro here on GitHub. It contains two apps - one is simple blank UWP app without any assets, second is a blank UWP app with many image content assets (which are however not used at all.

Expected behavior

When app does not use the content files in any way, they should not affect the launch time of the app (as the files are already deployed with the package, so the app should not manipulate them on start).

Screenshots

Profiler output

Notice the profiler shows all the launch time spent in Window Resized.

Profiler results

During debugging, you can see there is almost no CPU nor RAM activity during this wait time.

Version Info

NuGet package version: none required, classic UWP is sufficient

Windows 10 version Saw the problem?
Insider Build (xxxxx) Yes
November 2019 Update (18363) Yes
May 2019 Update (18362) Yes
October 2018 Update (17763) Yes
April 2018 Update (17134)
Fall Creators Update (16299)
Creators Update (15063)
Device form factor Saw the problem?
Desktop Yes
Mobile Yes
Xbox
Surface Hub
IoT

Additional context

Noticed this long ago with my app which has a lot of content icon images, but now I finally found out what is the root cause of it launching this slow.

ranjeshj commented 4 years ago

@Austin-Lamb @bartekk8 The repro is with just the platform bits (no winUI).

MartinZikmund commented 4 years ago

@ranjeshj That is true, it would not matter if I added Microsoft.UI. Unfortunately there is no better place to report UWP issues (that would be seen by the developers), that's why I posted the problem here. I will repost it on Windows Feedback too, but I am not sure it will reach the developer team from there.

ranjeshj commented 4 years ago

@MartinZikmund You have the correct repo :). With WinUI3 the platform bits are being moved out of the OS. So we can track this issue here. Thanks for reporting.

bartjroos commented 2 years ago

Hi guys, I'm having the exact same issue. Just wondering if anyone has found a solution and/or source of the problem yet, thanks!

luttje commented 2 years ago

I'm also running into this issue and discovered that it's irrelevant if there's many Assets included in the .csproj (as is the case in the original posters' repo). As long as there are a lot of assets in the AppX output directory, the slowdown occurs. The hang occurs on rootPage.Navigate in the App.xaml.cs.

itsWindows11 commented 1 year ago

Apparently it also has to do with the image size on my end, I've compressed a few images in the app assets and the startup time went to just 3 seconds on debug from around 11 seconds. It's not the sample repro project shared here that I tried this with, though.

MartinZikmund commented 1 year ago

@bartjroos My workaround here was to add the assets into a single .zip file, which I extract to ApplicationData folder on first launch. Then, I reference the files via ms-appdata:///Local/ instead of ms-appx. It means the app takes up twice the storage space though, so it is not a "proper" solution. On the other hand, this way the app launches very fast, especially on second and subsequent launches, where the extraction can be skipped.