The size of the assembly varies between .NET 7.0 and .NET 8.0.
Description
I have developed a custom assembly where we have incorporated a ResourceDictionary file for theme-related purposes. When compiling the assembly in Release-xml, its size is larger in .NET 8.0 compared to .NET 7.0.
While removing the ResourceDictionary file, the size is even in both .NET 7.0 and .NET 8.0
Please note: The increase in assembly size is attributed to adding code in the XAML ResourceDictionary page.
Video :
https://github.com/dotnet/maui/assets/102580874/78586dc9-c880-4c46-9bf7-564de0f3c316
Steps to Reproduce
1.Obtain the CustomAssembly project from the github link 2.Compile the project in the Release-Xml, you can observe the difference sizes between the .net7.0 Android and .net8.0 Android 3.The size increased between .NET 7.0 and NET 8.0 only if we add ResourceDictionary file on the CustomAssembly The increase in assembly size is attributed to adding code in the XAML ResourceDictionary page
Link to public reproduction project repository
https://github.com/Ahamed-Ali/AssemblySizeIssue
Version with bug
8.0.3
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
iOS, Android, Windows, macOS
Affected platform versions
No response
Did you find any workaround?
No
Relevant log output
No response
@jonathanpeppers thoughts?
MSIL is not a very compressed format. And it kind of makes sense that a declarative language like XAML would expand a bit when it is translated to IL in Release mode. Still seems surprising, though.
@Ahamed-Ali can you share the two files here?
Hi @Ahamed-Ali. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
Hi jonathanpeppers ,
.Please Obtain the tested CustomAssembly project from the below github link
https://github.com/Ahamed-Ali/AssemblySizeIssue
@Ahamed-Ali using this tool, you can see the "size" of types based on IL.
Debug:
Type Members IL Size References in other assemblies
1) <Module> 0 0 0
2) MauiAssemblyC.Themes.AThemeDictionary 4 105 0
3) MauiAssemblyC.Themes.AThemeResourceDictionary 7 146 0
4) MauiAssemblyC.Themes.AVisuals 3 0 0
5) MauiAssemblyC.Themes.DarkThemeColors 2 35 0
6) MauiAssemblyC.Themes.DefaultTheme 3 52 0
7) MauiAssemblyC.Themes.LightThemeColors 2 35 0
Release
Type Members IL Size References in other assemblies
1) <Module> 0 0 0
2) MauiAssemblyC.Themes.AThemeDictionary 4 80 0
3) MauiAssemblyC.Themes.AThemeResourceDictionary 7 108 0
4) MauiAssemblyC.Themes.AVisuals 3 0 0
5) MauiAssemblyC.Themes.DarkThemeColors 2 42724 0
6) MauiAssemblyC.Themes.DefaultTheme 3 122 0
7) MauiAssemblyC.Themes.LightThemeColors 2 42724 0
The IL is larger than the XAML is in text format.
The actual size doesn't seem to be that bad, considering the 200MB app store limit:
> (ls .\bin\Debug\net8.0\MauiAssemblyC.dll).Length
50176
> (ls .\bin\Release\net8.0\MauiAssemblyC.dll).Length
100864
What is your expectation here?
If you like, you can disable XamlCompilation in Release mode at the cost of worse performance. Which is more important for your app: size or speed?
Hi @Ahamed-Ali. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.
Hi @jonathanpeppers
You are currently comparing the assembly sizes of .NET 8 in both Release and Debug modes. However, our issue lies in the considerable size difference observed when comparing the assembly sizes of .NET 7.0 Android and .NET 8.0 Android in the Release-xml. Therefore, we kindly request a comparison of assembly sizes between .NET 7.0 and .NET 8.0 across various platforms, including Android and others
Please note: The increase in assembly size in .NET 8.0 is attributed to adding code in the XAML ResourceDictionary page.
We have also attached the comparison video for your reference in the description
@Ahamed-Ali what is the size difference you see? Is it less than 100kb?
If we were working on app size, this doesn't even feel like "low hanging fruit" to me. We would be better off working on this issue to improve app size by multiple MBs instead:
- https://github.com/dotnet/maui/issues/18658
Hi @Ahamed-Ali. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.
Hi @jonathanpeppers
Question : what is the size difference you see? Is it less than 100kb?
The assembly size increases in .NET 8.0 when compiling in release-xml, particularly with a large number of code lines in the ResourceDictionary file. For example, if there are more than 3000 lines of code, the size difference between .NET 8.0 and .NET 7.0 can exceed 100 KB. The size increase is proportional to the number of code lines in the ResourceDictionary file.
@Ahamed-Ali you might be interested in: https://github.com/dotnet/maui/pull/19945
It seems to significantly reduce the amount of IL, from the dotnet new maui template:
108544 mauibefore.dll
81920 mauiafter.dll
can you please open this github issue?, it seems to be closed