You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 25, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Feb 25, 2026. It is now read-only.
Reduce the toolkit impact on application size #3145
Trying to know what is the impact of the toolkit on the application final size, I've created two blank applications using Visual Studio. On one of them, I've added a dependency to Microsoft.Toolkit.Uwp.UI. I've only added the nuget dependency. I'm not using anything from the library.
Here are the sizes of the applications' dll when compiled in release using .Net Native:
x86
x64
Default blank app
748
919
Using Toolkit
6,171
7,253
Values are in KB. .Net Native directives' files are empty..
This huge impact comes from the fact that the blank app template is super minimal.
On our application, we are seeing a 2MB increase on both x86 and x64. This is still an important impact (knowing that nothing is used).
Is there a way to reduce the impact of the toolkit on the final binary size ?
Removing the Json.NET dependency should help in the future, that's tracked by this item: #3060, not sure if that'll line up for the 7.0 release though as there's a blocking bug in the System.Text.Json package, which is still another dependent package until .NET 5.
There may be an opportunity to investigate where we're using this dependency and clean that up or isolate it though.
Reacted by Vincent
ghost added a commit that references this issue on Sep 10, 2020
@vgromfeld can you add some more details here about your recent investigations, especially in regards to the XAML Metadata stuff you looked at recently?
Yes, looking at the symbols available in the final binary, I've found that even without any runtime directive, the binary still contains a lot of symbols related to the community toolkit. My initial guess was that since they are not used, they should have been automatically removed. But, it is not the case.
Looking at the app XamlTypeInfo, I found that a Microsoft_Toolkit_UWP_UI_Controls_Provider instance is added to an _otherProviders list. This class is generated by the XAML compiler in order to build the controls/dependencies. This is the one pulling all the references for all the unused controls. It contains a link to each control available from the community toolkit...
The XAML compiler has a DoNotGenerateOtherProviders control flag to force it to not automatically include the third party XamlTypeInfo files into the application main XamlTypeInfo. I've enabled it in a sample app but didn't see the impact I was expecting.
I first try with a blank app containing only a WrapPanel:
The app compiled and worked as expected.
It changes the binary size from 5 497Kb (default compiler behavior) to 5 119Kb (DoNotGenerateOtherProviders flag enabled). This saves only 378 Kb.
The final binary was still containing symbols of unused controls like BladeItem.
I also tried with a more "complicated" control: InAppNotification.
I faced a lot of Windows.UI.Xaml.Markup.XamlParseException in the runtime code when using the DoNotGenerateOtherProviders flag
Those exceptions do not contain any useful information about the issue 😥.
After investigation, it appears that they come from missing entries for StretchChild, CameraPreview and others in the app's XamlTypeInfo.
In the end, after adding empty styles to force them to be part of the app XamlTypeInfo, I get a working app.
The application binary's size goes from 5 502Kb to 5 299Kb. It decreases only by 203Kb.
I suspect all the static dependency properties to be the remaining roots to the controls symbols. Because they are static fields, they are not removed by .Net Native. I t guess that this is why changing the XAML compiler behavior is not helping that much. We can try to replace the dependency properties fields by properties as we've done for some classes but I'm not sure if the XAML runtime will like that...
Reducing the number of controls in each package, can be a good way to limit the impact on the app binary.
Obviously if you use multiple packages, the additional overhead starts to minimize with shared dependencies between some of the higher-up packages of Controls. If you just needed one individual package, this gives us a good idea of the overhead that brings.
Here's the whole latest breakdown from the final bit of work we're doing in #3676:
@vgromfeld preview4 was even before some of these refactors, so that's good to hear! There's the latest instructions about grabbing PR packages here.
Build 7.0.0-build.749.ge410992e4e has the new 'Core' package being worked on in #3676, so I'd be curious what different that makes, and if you feel that is acceptable or if we should split 'Core' into 2 packages of roughly half the size each?
Hum, when I tried using the Microsoft.Toolkit.Uwp.UI package from 7.0.0-build.749.ge410992e4e the app's dll size is 4,162Kb which is still better than before but not as good as 7.0.0-preview 4 which was 1Mb 🤔
Hum, when I tried using the Microsoft.Toolkit.Uwp.UI package from 7.0.0-build.749.ge410992e4e the app's dll size is 4,162Kb which is still better than before but not as good as 7.0.0-preview 4 which was 1Mb 🤔
Well, that's confusing... Preview4 added both the Behaviors dependency and System.Text.Json which we've now removed... I mean the UI dll itself is like 150kb only, so I don't see how there could be that big a swing...?
There shouldn't be anything different in the build process between the PR and preview branches, it's the same pipeline...
Looking at the content of both binaries, using the 7.0.0-build.749.ge410992e4e package pulls a lot of Xml related types which were not part of preview 4.
I can see System.Xml.*, `System.Runtime.Serialization.Xml*. types in the pdb (using PDB Viewer).
@vgromfeld hmmm, I wonder if that's because of #3637? I didn't think that using the existing platform stuff should matter to overhead? Is this because we construct one by default, is there a better pattern we can use here if it's not being used?
@vgromfeld alright, I've been able to dig into this a little bit. I can grab the .NET Native size diff in the Smoke Test script now too. Definitely seems like some of the initial bloat is coming from the Microsoft.Toolkit.Uwp package:
I'm trying to get the older 7.0.0-preview4 branch to build locally to grab the numbers to compare, but there were minimal changes to this package done between then and now:
It's mainly the change we did in #3637, which is a bit more confusing.
I'll see what the numbers show for 7.0.0-preview4, I may have to configure pulling the raw NuGet packages down as building is troublesome since we updated to .NET 5 after that preview so those changes are all missing.
Took a while as our build system for the Smoke Tests is forcing to use the Nerdbank version, so I had to undo that stuff so I could force a build from the 7.0.0-preview4 nugets, but was able to finally get a proper comparison between the current main and 7.0.0-preview4 (both attached).
Definitely can see the difference in the minimum impact. The main question is to understand why, as I tried commenting out the changes entirely to the JsonObjectSerializer from #3637 and it didn't seem to have an impact...
I just did a quick investigation on C# based Windows Runtime Components (WRC). Converting Microsoft.Toolkit.Uwp to a Windows Runtime Component doesn't take much on a project file, just:
However, that introduces 440+ errors that need to be resolved, most of which are individually significant and require breaking changes. It's definitely not something we would tackle for 7.0. And we'd want to think about the pros vs. cons or if we pull out smaller chunks at a time which are more easily transferrable (this may make more sense in the UI package for things like Converters and Triggers, etc...) I also don't know how this world changes for .NET 5+ and C#/WinRT @azchohfi?
Doing some quick tests on relatively empty components, it does appear that a C# WRC is compiled into a winmd and would live outside the application dll. Therefore, it could potentially be more easily shared on the overall footprint of an app. If that WRC references a regular .NET Standard component, it appear that still lives outside of it and is included in the app dll, though the winmd file will still remain separate.
Going to look at seeing if we need the Uwp package as a dependency for the UI package.
Since generics in the UWP package were difficult, I decided to do some more investigations trying to just pull over the Converters and Triggers from the UI package to a Windows Runtime Component. However, the lack of inheritance and abstract classes made that fairly difficult for some. We were able to maybe relatively easily convert over the DependencyProperty constructs (needs more testing).
In the end though, the winmd produced was only like 40kb and there may be some trimming going on as the one in the AppX folder is only 18kb. I'm not sure where that ends up on disk, so I couldn't test dropping the full winmd in its place to see what would happen. Even then, the impact on the app due to system dependencies via .NET Native still seems to be the larger impact here compared to teasing out bits and pieces within a winmd. Especially with the extra restrictions that places on them?
i.e. If we had something large like the Controls package as whole which could be a winmd, then maybe it would make more sense.
I think we need to understand more of how the new world works in .NET 5+ before making a decision on this front as well.
Activity
michael-hawker commentedon Mar 2, 2020
Removing the Json.NET dependency should help in the future, that's tracked by this item: #3060, not sure if that'll line up for the 7.0 release though as there's a blocking bug in the
System.Text.Jsonpackage, which is still another dependent package until .NET 5.There may be an opportunity to investigate where we're using this dependency and clean that up or isolate it though.
Split Markdown.* from Controls package. (#3437)
michael-hawker commentedon Dec 4, 2020
@vgromfeld can you add some more details here about your recent investigations, especially in regards to the XAML Metadata stuff you looked at recently?
vgromfeld commentedon Dec 7, 2020
Yes, looking at the symbols available in the final binary, I've found that even without any runtime directive, the binary still contains a lot of symbols related to the community toolkit. My initial guess was that since they are not used, they should have been automatically removed. But, it is not the case.
Looking at the app
XamlTypeInfo, I found that aMicrosoft_Toolkit_UWP_UI_Controls_Providerinstance is added to an_otherProviderslist. This class is generated by the XAML compiler in order to build the controls/dependencies. This is the one pulling all the references for all the unused controls. It contains a link to each control available from the community toolkit...The XAML compiler has a
DoNotGenerateOtherProviderscontrol flag to force it to not automatically include the third partyXamlTypeInfofiles into the application mainXamlTypeInfo. I've enabled it in a sample app but didn't see the impact I was expecting.I first try with a blank app containing only a
WrapPanel:BladeItem.I also tried with a more "complicated" control:
InAppNotification.Windows.UI.Xaml.Markup.XamlParseExceptionin the runtime code when using the DoNotGenerateOtherProviders flagStretchChild,CameraPreviewand others in the app'sXamlTypeInfo.XamlTypeInfo, I get a working app.I suspect all the static dependency properties to be the remaining roots to the controls symbols. Because they are static fields, they are not removed by .Net Native. I t guess that this is why changing the XAML compiler behavior is not helping that much. We can try to replace the dependency properties fields by properties as we've done for some classes but I'm not sure if the XAML runtime will like that...
Reducing the number of controls in each package, can be a good way to limit the impact on the app binary.
michael-hawker commentedon Jan 22, 2021
FYI @vgromfeld @JustinXinLiu @rudyhuyn
Obviously if you use multiple packages, the additional overhead starts to minimize with shared dependencies between some of the higher-up packages of Controls. If you just needed one individual package, this gives us a good idea of the overhead that brings.
Here's the whole latest breakdown from the final bit of work we're doing in #3676:
vgromfeld commentedon Jan 22, 2021
I've rebuilt my sample app with the 7.0.0-preview 4 nuget package and the app's dll size has decreased from 6,171Kb to 1,800Kb (x86) 🎉
michael-hawker commentedon Jan 22, 2021
@vgromfeld preview4 was even before some of these refactors, so that's good to hear! There's the latest instructions about grabbing PR packages here.
Build 7.0.0-build.749.ge410992e4e has the new 'Core' package being worked on in #3676, so I'd be curious what different that makes, and if you feel that is acceptable or if we should split 'Core' into 2 packages of roughly half the size each?
vgromfeld commentedon Jan 22, 2021
Hum, when I tried using the
Microsoft.Toolkit.Uwp.UIpackage from 7.0.0-build.749.ge410992e4e the app's dll size is 4,162Kb which is still better than before but not as good as 7.0.0-preview 4 which was 1Mb 🤔michael-hawker commentedon Jan 22, 2021
Well, that's confusing... Preview4 added both the Behaviors dependency and
System.Text.Jsonwhich we've now removed... I mean the UI dll itself is like 150kb only, so I don't see how there could be that big a swing...?There shouldn't be anything different in the build process between the PR and preview branches, it's the same pipeline...
vgromfeld commentedon Jan 22, 2021
Looking at the content of both binaries, using the 7.0.0-build.749.ge410992e4e package pulls a lot of Xml related types which were not part of preview 4.
I can see
System.Xml.*, `System.Runtime.Serialization.Xml*. types in the pdb (using PDB Viewer).michael-hawker commentedon Jan 22, 2021
@vgromfeld hmmm, I wonder if that's because of #3637? I didn't think that using the existing platform stuff should matter to overhead? Is this because we construct one by default, is there a better pattern we can use here if it's not being used?
michael-hawker commentedon Jan 23, 2021
@vgromfeld alright, I've been able to dig into this a little bit. I can grab the .NET Native size diff in the Smoke Test script now too. Definitely seems like some of the initial bloat is coming from the
Microsoft.Toolkit.Uwppackage:I'm trying to get the older 7.0.0-preview4 branch to build locally to grab the numbers to compare, but there were minimal changes to this package done between then and now:
It's mainly the change we did in #3637, which is a bit more confusing.
I'll see what the numbers show for 7.0.0-preview4, I may have to configure pulling the raw NuGet packages down as building is troublesome since we updated to .NET 5 after that preview so those changes are all missing.
michael-hawker commentedon Jan 25, 2021
Took a while as our build system for the Smoke Tests is forcing to use the Nerdbank version, so I had to undo that stuff so I could force a build from the 7.0.0-preview4 nugets, but was able to finally get a proper comparison between the current main and 7.0.0-preview4 (both attached).
Definitely can see the difference in the minimum impact. The main question is to understand why, as I tried commenting out the changes entirely to the
JsonObjectSerializerfrom #3637 and it didn't seem to have an impact...FootPrintMain.txt
FootPrint7.0.0-preview4.txt
michael-hawker commentedon Jan 29, 2021
I just did a quick investigation on C# based Windows Runtime Components (WRC). Converting
Microsoft.Toolkit.Uwpto a Windows Runtime Component doesn't take much on a project file, just:However, that introduces 440+ errors that need to be resolved, most of which are individually significant and require breaking changes. It's definitely not something we would tackle for 7.0. And we'd want to think about the pros vs. cons or if we pull out smaller chunks at a time which are more easily transferrable (this may make more sense in the UI package for things like Converters and Triggers, etc...) I also don't know how this world changes for .NET 5+ and C#/WinRT @azchohfi?
Doing some quick tests on relatively empty components, it does appear that a C# WRC is compiled into a winmd and would live outside the application dll. Therefore, it could potentially be more easily shared on the overall footprint of an app. If that WRC references a regular .NET Standard component, it appear that still lives outside of it and is included in the app dll, though the winmd file will still remain separate.
Going to look at seeing if we need the Uwp package as a dependency for the UI package.
michael-hawker commentedon Jan 30, 2021
Since generics in the UWP package were difficult, I decided to do some more investigations trying to just pull over the Converters and Triggers from the UI package to a Windows Runtime Component. However, the lack of inheritance and abstract classes made that fairly difficult for some. We were able to maybe relatively easily convert over the
DependencyPropertyconstructs (needs more testing).In the end though, the winmd produced was only like 40kb and there may be some trimming going on as the one in the AppX folder is only 18kb. I'm not sure where that ends up on disk, so I couldn't test dropping the full winmd in its place to see what would happen. Even then, the impact on the app due to system dependencies via .NET Native still seems to be the larger impact here compared to teasing out bits and pieces within a winmd. Especially with the extra restrictions that places on them?
i.e. If we had something large like the Controls package as whole which could be a winmd, then maybe it would make more sense.
I think we need to understand more of how the new world works in .NET 5+ before making a decision on this front as well.