~eliasnaur/gio#371: 
widget/material, gofont, material/icons is imported by default

I have one app and I notice some increase in the file-size, noticeable for WebAssembly. I don't use widget/material, instead I use custom widgets and fonts.


However, I notice that the binary file contains fonts from GoFonts, icons from material/icons and also imports widget/material.

The source of those imports are from gio/app/window.go (https://github.com/gioui/gio/blob/main/app/window.go#L30).

I remove that import, and also remove the decorate() function. The size of the file comes down to 15.212 KB, from 17.170KB.

#I think the reason to gofont.Collection() exists is to prevent been imported by default. If I remember correctly, Gio used to import it by default, in the past. However, now, it's also importing golang.org/x/exp/shiny/materialdesign/icons by default.

Removing the decorate (and widget/material, and gofont) from window.go, it reduce the size:

Stardand: 17.170KB > 15.212 KB

GZip: 4.772KB > 3.907KB

Brotli: 2.936KB > 2.562KB

Of course, I'm not suggesting to remove the decorate. However, I think window.go could have a custom interface/function for Decoration, and it must be defined using some Option. In that case, widget/material will not be used by default and also allow to use custom decorations (I'm not sure if it's currently possible). But, I don't think it makes sense to have bigger binary file for Android, Windows, Javascript (...) for a feature that is not used.

Status
RESOLVED FIXED
Submitter
~inkeliz
Assigned to
No-one
Submitted
2 years ago
Updated
2 years ago
Labels
No labels applied.

~eliasnaur 2 years ago

Good points. I suspect gofont.Collection is the cause for almost all of the size increase. If so, I expect the size increase to go away once we have system font loading. If not, I'd like to know how widget/material or material/icons can take up significant space.

~egonelbre 2 years ago

In the mean time, an easy change would be to load only one of the gofont-s for decorations, not all of them.

~egonelbre 2 years ago

In the mean time, an easy change would be to load only one of the gofont-s for decorations, not all of them.

~eliasnaur 2 years ago

Good idea, ~egonelbre.

~inkeliz 2 years ago*

Using goweight (which is not precise):

  • 947 kB golang.org/x/exp/shiny/materialdesign/icons

  • 180 kB golang.org/x/image/font/gofont/gomonobolditalic
  • 176 kB golang.org/x/image/font/gofont/gomonoitalic
  • 171 kB golang.org/x/image/font/gofont/gomonobold
  • 167 kB golang.org/x/image/font/gofont/gomono
  • 158 kB golang.org/x/image/font/gofont/gomediumitalic
  • 150 kB golang.org/x/image/font/gofont/goitalic
  • 150 kB golang.org/x/image/font/gofont/gomedium
  • 147 kB golang.org/x/image/font/gofont/gobold
  • 143 kB golang.org/x/image/font/gofont/gosmallcapsitalic
  • 143 kB golang.org/x/image/font/gofont/goregular
  • 136 kB golang.org/x/image/font/gofont/gosmallcaps

Total of fonts: 1721 kB


  • 572 kB gioui.org/widget/material
  • 28 kB gioui.org/font/gofont

Considering goweight, that is 3268 kB. But, in reality it is just 1958 kB (?). I guess the compiler is smart enough to remove unused functions and variables, so most of those icons are removed, but not entire. The fonts is what takes most of the space, I guess.

~eliasnaur 2 years ago

Considering goweight, that is 3268 kB. But, in reality it is just 1958 kB (?). I guess the compiler is smart enough to remove unused functions and variables, so most of those icons are removed, but not entire. The fonts is what takes most of the space, I guess.

Right. Decorations use only a handful icons from the icons package, which is why I think measuring the weight of individual packages before the linker removes unused functions and variables is misleading. However, as Egon indicated, the linker can't see through the unused fonts in gofont.Collection. A better experiment is to hack gofont.Collection to only load one font and measure the size.

~egonelbre 2 years ago

Decorations package doesn't use icons package, the dependency probably comes from elsewhere. https://github.com/gioui/gio/blob/main/widget/material/decorations.go#L146

Seems like radio & check button is the culprit: https://github.com/gioui/gio/blob/main/widget/material/theme.go#L61

~egonelbre 2 years ago

~inkeliz which tool are you exactly using? I don't see materialdesign/icons showing up using goda weight.

Are you using a tool that examines the binary or a tool that examines the packages?

~inkeliz 2 years ago

I used goweight (https://github.com/jondot/goweight), but as I said, that tool is not precise.

I guess the major issue is the fonts, I'll test removing all fonts, but keeping anything else and them removing everything.

-- Lucas Rodrigues inkeliz@inkeliz.com

On Sun, Mar 6, 2022, at 7:24 AM, ~egonelbre wrote:

~inkeliz which tool are you exactly using? I don't see materialdesign/icons showing up using goda weight.

Are you using a tool that examines the binary or a tool that examines the packages?

-- View on the web: https://todo.sr.ht/~eliasnaur/gio/371#event-143680

Attachments:

  • signature.asc

~eliasnaur REPORTED FIXED 2 years ago

Inkeliz referenced this ticket in commit b1dba5f.

Register here or Log in to comment, or comment via email.