-
Notifications
You must be signed in to change notification settings - Fork 701
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
Comments
@KirillPom is this app size issue specific to the preview1 version of Winui3 or were you noticing it with other Winui apps as well? |
@MikeHillberg @Austin-Lamb for FYI |
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.
If there is a mechanism to share WinUI components system-wide. This is opposite to the goal of extracting WinUI from the OS. |
@huoyaoyuan . Thank you. |
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. |
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 |
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? |
As far as I am aware there are two ways to reduce the size of your WinUI3 app. 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 |
Closing as this appears to have multiple answer comments and has not seen activity since July. |
What about publishing to Microsoft Store? Will the MS store download necessary dependency? The console app has size about 100mb. |
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?
The text was updated successfully, but these errors were encountered: