Mahapps.metro: Reduce build size

Created on 22 May 2020  路  11Comments  路  Source: MahApps/MahApps.Metro

Is your feature request related to a problem? Please describe.
I currently use MahApps.Metro.dll 1.6.5 which is about 1MB in size. The latest version of MahApps.Metro from master builds to 3MB. This will add about 20% to my installer size.

Describe the solution you'd like
Is there any guidance or a method to produce a 'light' version with optional dependencies or metadata removed?

Feature Request

Most helpful comment

@timunie I understand the reasons, just wanted to understand the perspective. Thanks and congratulations to the team on putting v2.0.0 out. It is awesome.

All 11 comments

This is because of the themes and assets. Each theme is 80KB (40KB for dark and 40KB for light), and there are 23 different themes. It would be nice if there was a version where you can just grab the themes you need. There's also a huge ttf of 260KB used only for a checkbox style. You can strip some of it out manually.

So while we could reduce the size of the library i am wondering what the use case for this would be?
I mean 3 MB are not that much.
You say it's 20% of your installer size. What makes up the remaining 80%?
How much of your application is based on MahApps.Metro? How does that feature set compare, in relation, to non MahApps.Metro based features?

What would be the real benefit if we, for example, reduced the size to ~1.8 MB?
How would you shape a "light" version? What should be included and what not?
And, maybe most importantly, who will maintain the result?

@batzen thanks for your reply, I think what I'm looking for here is some detail on where the size increase has come from (I assume styles etc where part of v1.x already) and if there is something I can remove in my own build (if required).

My use case is for https://certifytheweb.com - this is a (commercial and open source) desktop app used to manage ACME certificates primarily on windows. I spent yesterday shaving off a couple of MB that had crept in via new dependencies such as Azure Key Vault and trimming my own builds of certain other libraries. I have not yet attempted to upgrade to MahApps.Metro v2.

My installer is currently 10MB and for me this means 877GB of downloads per year, which then results in data transfer fees. Admittedly that's not huge, but if there was an opportunity to reduce file size it would help and I can use the spare money to sponsor more github contributors :) Smaller setup also means quicker automatic updates for end users.

I can see the viewpoint that file size would be considered trivial in most cases, it's not a deal breaker but it's something to keep an eye on.

Hi @webprofusion-chrisc ,
First of all I think your point is much clearer now. The increase of the file size comes with a lot of benefits:

  • more Styles
  • more options to individualize the Style
  • more / better Controls
  • Windows 10 Font-Symbols even on older machines (I still need to target Win7 :disappointed: )
  • more Theming Options
  • ...

Nevertheless you can reduce the size of the App if you can build MahApps on your own:

  1. Edit the File Styles\Themes\GeneratorParameters.json to only contain the needed ColorScheme(s). Make sure you leave the BaseColorSchemes untouched. Delete all current Themes in this folder except for the Template.xaml
  2. If you do not use the Win10 Checkbox, you can set the BuildAction of Assets\segmdl2.ttf to None.
    Result:
    image

With the ThemeManager from @batzen you can create the missing Themes at Runtime. Here is an example: https://github.com/MahApps/MahApps.Metro/pull/3710

Happy file size reducing
Tim

Hi Tim,

If it is not too much to ask, can you please share the idea behind using a font instead of a path in MahApps.Styles.CheckBox.Win10 which forces the use of an extra FontIcon class and template, and the segmdl2.ttf font? We are using paths in MahApps.Styles.CheckBox style anyways.

Also, can the generated style files use merged dictionaries as there is a lot of repeated styles and bindings?

Just asking out of curiosity.

Regards,
Yogesh

@timunie excellent, thanks very much for your suggestions!

If it is not too much to ask, can you please share the idea behind using a font instead of a path in MahApps.Styles.CheckBox.Win10 which forces the use of an extra FontIcon class and template, and the segmdl2.ttf font? We are using paths in MahApps.Styles.CheckBox style anyways.

@yjagota Because the Win10 style use exactly then the same Font character. Yes, it's also possible to use a Path, but you must first extract the path from the font, which is not exactly the same as the font and let the checkbox looks different with the different brushes (checked, mouse hover).

The font is included, because of

Windows 10 Font-Symbols even on older machines (I still need to target Win7 馃槥 )

I understood the part about exactly matching Win10 style and including the font for Win7. I just wanted to know why a path was not used instead because both the symbols are pretty straightforward to define in a path. One in fact does not even need a path as a rectangle would suffice. Hence the question.

@yjagota one last statement just from my point of view. The font has much more characters that are so useful to me, and I can now use them e.g. in the HamburgerMenu I would be very sad if I loose this due to some KB of size.

I'm happy with the suggested workarounds from @timunie. Closing.

[Edit: removing unused themes and setting font embedded resource to 'None' reduces release .dll size to 1.2MB]

@timunie I understand the reasons, just wanted to understand the perspective. Thanks and congratulations to the team on putting v2.0.0 out. It is awesome.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  18Comments

ghiboz picture ghiboz  路  11Comments

StickNitro picture StickNitro  路  11Comments

SteffanDonal picture SteffanDonal  路  11Comments

benjamin275 picture benjamin275  路  17Comments