maui icon indicating copy to clipboard operation
maui copied to clipboard

The size of the assembly varies between .NET 7.0 and .NET 8.0.

Open Ahamed-Ali opened this issue 2 years ago • 11 comments

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

Ahamed-Ali avatar Dec 12 '23 14:12 Ahamed-Ali

@jonathanpeppers thoughts?

PureWeen avatar Dec 12 '23 19:12 PureWeen

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?

jonathanpeppers avatar Dec 12 '23 20:12 jonathanpeppers

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.

ghost avatar Dec 13 '23 22:12 ghost

Hi jonathanpeppers ,

.Please Obtain the tested CustomAssembly project from the below github link

https://github.com/Ahamed-Ali/AssemblySizeIssue

Ahamed-Ali avatar Dec 14 '23 05:12 Ahamed-Ali

@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?

jonathanpeppers avatar Dec 14 '23 14:12 jonathanpeppers

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.

ghost avatar Dec 14 '23 19:12 ghost

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.

ghost avatar Dec 18 '23 20:12 ghost

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 avatar Dec 19 '23 09:12 Ahamed-Ali

@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

jonathanpeppers avatar Jan 03 '24 15:01 jonathanpeppers

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.

ghost avatar Jan 03 '24 15:01 ghost

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.

ghost avatar Jan 08 '24 00:01 ghost

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 avatar Jan 18 '24 04:01 Ahamed-Ali

@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

jonathanpeppers avatar Jan 18 '24 14:01 jonathanpeppers

can you please open this github issue?, it seems to be closed

Ahamed-Ali avatar Feb 05 '24 06:02 Ahamed-Ali