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

App size is huge #2579

Closed
KirillPom opened this issue Jun 1, 2020 · 11 comments
Closed

App size is huge #2579

KirillPom opened this issue Jun 1, 2020 · 11 comments
Labels
area-NugetPackage Issue with the nuget package developer experience (e.g. build error, missing files) product-winui3 WinUI 3 issues question team-Markup Issue for the Markup team

Comments

@KirillPom
Copy link

Created blank C# WinUI3 app (packaged)
After compilation app size in 127 mb and package size is 250+ Mb.
I compare it to simple WPF app size of 2-3 Mb.

Why so large size of app and package? How to lower it to 1,2,3 Mb?

@msft-github-bot msft-github-bot added the needs-triage Issue needs to be triaged by the area owners label Jun 1, 2020
@StephenLPeters
Copy link
Contributor

@KirillPom is this app size issue specific to the preview1 version of Winui3 or were you noticing it with other Winui apps as well?

@StephenLPeters
Copy link
Contributor

@MikeHillberg @Austin-Lamb for FYI

@StephenLPeters StephenLPeters added area-NugetPackage Issue with the nuget package developer experience (e.g. build error, missing files) product-winui3 WinUI 3 issues labels Jun 1, 2020
@huoyaoyuan
Copy link

I compare it to simple WPF app size of 2-3 Mb.

You should be comparing with .NET Framework or .NET Core framework dependent application. See https://docs.microsoft.com/en-us/dotnet/core/deploying/ .

Currently the default template creates a self-contained application. It's not related to WinUI.

Total size of WinUI introduced files are about 32MB.

How to lower it to 1,2,3 Mb?

If there is a mechanism to share WinUI components system-wide. This is opposite to the goal of extracting WinUI from the OS.

@KirillPom
Copy link
Author

@huoyaoyuan . Thank you.
But the question is - do you really need 127Mb of binaries just to show simple window with one button.
image

@huoyaoyuan
Copy link

do you really need 127Mb of binaries just to show simple window with one button

Then the topic comes to that how to delete unused code.

For .NET side, there is trimming tool, but still imperfect for UI applications.

Currently the SDK cannot analyze what you need. It can only grab everything what they support now.

I'd expect the successor of .NET native to trim across managed and native boundary.

@StephenLPeters StephenLPeters removed the needs-triage Issue needs to be triaged by the area owners label Jun 2, 2020
@ringoz
Copy link

ringoz commented Aug 4, 2021

image
The same gallery app is 10 times bigger, despite reduced functionality.
I'll stick with native XAML for now...

@Austin-Lamb
Copy link

App size is a tricky thing to explain because of some cool things that the OS AppxDeploymentServer does. If you crack open the WinUI 3 Controls Gallery app package, or look at the files it puts on disk after install, you'll see some files like Microsoft.Windows.SDK.NET.dll and Microsoft.WinUI.dll, which are quite large - these are the C#/WinRT projection assemblies for the Windows SDK and WinUI 3. The good news is that if multiple apps get installed with the same version of these assemblies, the AppxDeploymentServer is smart enough to notice the same files are being deployed multiple times and it will instead link them (I think hardlink?) so they don't exist multiple times on-disk.

This helps when common NuGet libraries are used in apps as you don't pay for multiple copies on disk, but each app can update independently still so it's not the old DLL Hell problem. It just optimizes disk space automatically as a benefit of being a packaged application. So you can think of this, in some sense, as a one-time on-disk usage for all of the Windows App SDK, then each app shares these. The reason the app appears so much larger than using the in-OS version of XAML is that the in-OS XAML version of the app relies on many libraries too (like Windows.UI.Xaml.dll) that are in the system32 folder, instead of coming from a framework package - they still share between processes using the same version of the framework, just like in the WinUI 3 version, but the accounting is different as the OS files aren't counted in the size of the app as seen in Settings.

Internally we are discussing tweaking the deployment model here to possibly put these files in the Windows App SDK Framework Package to make this a bit clearer. Doing so would not change the disk footprint due to the sharing I mentioned, but it may make it clearer for accounting purposes.

Separately, this thread touched on the topic of IL trimming - currently WinUI 3, like WPF, does not support IL trimming because the XAML markup language and its binary variants (BAML for WPF, XBF for WinUI 3) uses things like Reflection in some cases (such as Binding) to find the right thing to hook up to, or in some cases for type activation entirely. In the future it may be possible for XAML to inform the IL trimmer about what types/properties it sees as "live" so the trimmer can avoid removing them, but at this time it doesn't so if you trim your WinUI app, you'll very likely find it crashes because things were removed that were only used via markup. See this similar issue in the WPF repo: dotnet/wpf#3811

@gautambjain
Copy link

I am really concerned about the app size too.

Can someone answer just one question?

What would be my Win UI 3 app size if it were the first app to be installed on a freshly installed Windows 10 OS?

@bpulliam bpulliam added the team-Markup Issue for the Markup team label Oct 29, 2022
@Pinguin2001
Copy link

Pinguin2001 commented Jul 12, 2023

As far as I am aware there are two ways to reduce the size of your WinUI3 app.
If you are creating an unpackaged WinUI app (I havent tested packaged apps yet), ensure you do not self-contain the .NET Runtime nor the WinAppSdk Runtime.

If you add the following property to your csproj (https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/use-windows-app-sdk-run-time)

<WindowsAppSDKBootstrapAutoInitializeOptions_OnNoMatch_ShowUI>true</WindowsAppSDKBootstrapAutoInitializeOptions_OnNoMatch_ShowUI>

Your exe will detect if the required WinAppSdk runtime is present on the system, if it isnt, it will prompt the user to download it.

and ensure the following isnt present

<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>

Your app size will reduce to ~30mb, at least in my testing this is the case

@duncanmacmichael
Copy link
Member

Closing as this appears to have multiple answer comments and has not seen activity since July.

@steam3d
Copy link

steam3d commented Dec 15, 2023

What about publishing to Microsoft Store? Will the MS store download necessary dependency?
I work on widget (https://learn.microsoft.com/en-us/windows/apps/develop/widgets/implement-widget-provider-cs)

The console app has size about 100mb.

@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Dec 15, 2023
@codendone codendone removed the needs-triage Issue needs to be triaged by the area owners label Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-NugetPackage Issue with the nuget package developer experience (e.g. build error, missing files) product-winui3 WinUI 3 issues question team-Markup Issue for the Markup team
Projects
None yet
Development

No branches or pull requests