fyne-io / fyne

Cross platform GUI toolkit in Go inspired by Material Design
https://fyne.io/
Other
24.48k stars 1.36k forks source link

Built binary is too large #5008

Open yms2772 opened 1 month ago

yms2772 commented 1 month ago

Checklist

Describe the bug

Windows 11

$ go build -o test.exe
$ du -h test.exe
103M    test.exe

macOS Sonoma 14.5

$ go build -o test
$ du -h test
 62M    test

The built binary size is very much larger than 2.4.x version of fyne. In 2.4.x version, it came out to about 30MB on a Windows build, but now it's more than triple that size with the same code.

How to reproduce

.

Screenshots

No response

Example code

.

Fyne version

2.5.0

Go compiler version

1.22.1

Operating system and version

M1 macOS Sonoma 14.5

Additional Information

No response

andydotxyz commented 1 month ago

This makes no sense unfortunately - there are not new big bundled items in 2.5.0 and the build on my macOS computer is just 12MB (15MB with debug symbols).

Please make sure you have the fyne CLI installed and up to date and see what the resulting size is from fyne package -release.

andydotxyz commented 1 month ago

Just to follow up there is one possible cause - the icon used to be embedded only from packaging but now it will be included in "go build" if you have FyneApp.toml. Please make sure your app Icon.png is closer to 12KB and not 32MB ;).

yms2772 commented 1 month ago
  1. I have the latest fyne CLI, but I don’t use fyne package, I use go build.
  2. I have no icon image and FyneApp.toml.
  3. When I build with -ldflags=“-s -w” on Windows 11, the size is about 40MB, not 100MB.
  4. There's nothing changed except for the fyne version, but why is the size 3 times higher?
MatejMagat305 commented 1 month ago

did you try same program without fyne?

andydotxyz commented 1 month ago

When I build with -ldflags=“-s -w” on Windows 11, the size is about 40MB, not 100MB.

This step would be performed automatically by "fyne package -release".

There's nothing changed except for the fyne version, but why is the size 3 times higher?

I cannot guess, nobody else has reported this and if it had happened during development the change would not have been accepted.

Please check with the "hello world" app to eliminate the possibility of something relating to your app triggering bundled items.

yms2772 commented 1 month ago

@andydotxyz Here are two go.mod with different fyne versions and the build results of each.

go.mod (fyne v2.4.5)

module test

go 1.22

require (
    fyne.io/fyne/v2 v2.4.5
    github.com/bwmarrin/discordgo v0.28.1
    github.com/google/uuid v1.6.0
    github.com/gotd/td v0.106.0
    github.com/hirokisan/bybit/v2 v2.32.0
    github.com/pkg/errors v0.9.1
    github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
)

require (
    fyne.io/systray v1.11.0 // indirect
    github.com/cenkalti/backoff/v4 v4.3.0 // indirect
    github.com/davecgh/go-spew v1.1.1 // indirect
    github.com/fredbi/uri v1.1.0 // indirect
    github.com/fsnotify/fsnotify v1.7.0 // indirect
    github.com/fyne-io/gl-js v0.0.0-20220119005834-d2da28d9ccfe // indirect
    github.com/fyne-io/glfw-js v0.0.0-20240101223322-6e1efdc71b7a // indirect
    github.com/fyne-io/image v0.0.0-20220602074514-4956b0afb3d2 // indirect
    github.com/go-faster/errors v0.7.1 // indirect
    github.com/go-faster/jx v1.1.0 // indirect
    github.com/go-faster/xor v1.0.0 // indirect
    github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 // indirect
    github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a // indirect
    github.com/go-text/render v0.1.0 // indirect
    github.com/go-text/typesetting v0.1.0 // indirect
    github.com/godbus/dbus/v5 v5.1.0 // indirect
    github.com/google/go-querystring v1.1.0 // indirect
    github.com/gopherjs/gopherjs v1.17.2 // indirect
    github.com/gorilla/websocket v1.5.3 // indirect
    github.com/gotd/ige v0.2.2 // indirect
    github.com/gotd/neo v0.1.5 // indirect
    github.com/jsummers/gobmp v0.0.0-20151104160322-e2ba15ffa76e // indirect
    github.com/klauspost/compress v1.17.9 // indirect
    github.com/pmezard/go-difflib v1.0.0 // indirect
    github.com/segmentio/asm v1.2.0 // indirect
    github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c // indirect
    github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef // indirect
    github.com/stretchr/testify v1.9.0 // indirect
    github.com/yuin/goldmark v1.7.1 // indirect
    go.opentelemetry.io/otel v1.28.0 // indirect
    go.opentelemetry.io/otel/trace v1.28.0 // indirect
    go.uber.org/atomic v1.11.0 // indirect
    go.uber.org/multierr v1.11.0 // indirect
    go.uber.org/zap v1.27.0 // indirect
    golang.org/x/crypto v0.25.0 // indirect
    golang.org/x/image v0.18.0 // indirect
    golang.org/x/mobile v0.0.0-20231127183840-76ac6878050a // indirect
    golang.org/x/net v0.27.0 // indirect
    golang.org/x/sync v0.7.0 // indirect
    golang.org/x/sys v0.22.0 // indirect
    golang.org/x/text v0.16.0 // indirect
    gopkg.in/yaml.v3 v3.0.1 // indirect
    honnef.co/go/js/dom v0.0.0-20210725211120-f030747120f2 // indirect
    nhooyr.io/websocket v1.8.11 // indirect
    rsc.io/qr v0.2.0 // indirect
)

replace github.com/hirokisan/bybit/v2 v2.32.0 => ../../bybit
PS C:\test> go build -v -o test.exe
PS C:\test> (Get-Item test.exe).Length / 1MB
51.9019804000854

go.mod (fyne v2.5.0)

module test

go 1.22

require (
    fyne.io/fyne/v2 v2.5.0
    github.com/bwmarrin/discordgo v0.28.1
    github.com/google/uuid v1.6.0
    github.com/gotd/td v0.106.0
    github.com/hirokisan/bybit/v2 v2.32.0
    github.com/pkg/errors v0.9.1
    github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
)

require (
    fyne.io/systray v1.11.0 // indirect
    github.com/BurntSushi/toml v1.4.0 // indirect
    github.com/cenkalti/backoff/v4 v4.3.0 // indirect
    github.com/davecgh/go-spew v1.1.1 // indirect
    github.com/fredbi/uri v1.1.0 // indirect
    github.com/fsnotify/fsnotify v1.7.0 // indirect
    github.com/fyne-io/gl-js v0.0.0-20220119005834-d2da28d9ccfe // indirect
    github.com/fyne-io/glfw-js v0.0.0-20240101223322-6e1efdc71b7a // indirect
    github.com/fyne-io/image v0.0.0-20220602074514-4956b0afb3d2 // indirect
    github.com/go-faster/errors v0.7.1 // indirect
    github.com/go-faster/jx v1.1.0 // indirect
    github.com/go-faster/xor v1.0.0 // indirect
    github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 // indirect
    github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a // indirect
    github.com/go-text/render v0.1.0 // indirect
    github.com/go-text/typesetting v0.1.0 // indirect
    github.com/godbus/dbus/v5 v5.1.0 // indirect
    github.com/google/go-querystring v1.1.0 // indirect
    github.com/gopherjs/gopherjs v1.17.2 // indirect
    github.com/gorilla/websocket v1.5.3 // indirect
    github.com/gotd/ige v0.2.2 // indirect
    github.com/gotd/neo v0.1.5 // indirect
    github.com/jeandeaual/go-locale v0.0.0-20240223122105-ce5225dcaa49 // indirect
    github.com/jsummers/gobmp v0.0.0-20151104160322-e2ba15ffa76e // indirect
    github.com/klauspost/compress v1.17.9 // indirect
    github.com/nicksnyder/go-i18n/v2 v2.4.0 // indirect
    github.com/pmezard/go-difflib v1.0.0 // indirect
    github.com/rymdport/portal v0.2.2 // indirect
    github.com/segmentio/asm v1.2.0 // indirect
    github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c // indirect
    github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef // indirect
    github.com/stretchr/testify v1.9.0 // indirect
    github.com/yuin/goldmark v1.7.1 // indirect
    go.opentelemetry.io/otel v1.28.0 // indirect
    go.opentelemetry.io/otel/trace v1.28.0 // indirect
    go.uber.org/atomic v1.11.0 // indirect
    go.uber.org/multierr v1.11.0 // indirect
    go.uber.org/zap v1.27.0 // indirect
    golang.org/x/crypto v0.25.0 // indirect
    golang.org/x/image v0.18.0 // indirect
    golang.org/x/mobile v0.0.0-20231127183840-76ac6878050a // indirect
    golang.org/x/net v0.27.0 // indirect
    golang.org/x/sync v0.7.0 // indirect
    golang.org/x/sys v0.22.0 // indirect
    golang.org/x/text v0.16.0 // indirect
    gopkg.in/yaml.v3 v3.0.1 // indirect
    nhooyr.io/websocket v1.8.11 // indirect
    rsc.io/qr v0.2.0 // indirect
)

replace github.com/hirokisan/bybit/v2 v2.32.0 => ../../bybit
PS C:\test> go build -v -o test.exe
PS C:\test> (Get-Item test.exe).Length / 1MB
103.852210044861
andydotxyz commented 1 month ago

Thanks for the info. Something is strange though - it went from over 3 the size to approximately 2...

Is this running on the same computer?

yms2772 commented 1 month ago

@andydotxyz The 30MB that I wrote in this issue was likely from a past build under different conditions. The 2* difference is correct.

The attachments below are the results of doing go tool nm for each version.

fyne v2.4.5

go_tool_nm_v2.4.5.txt (2MB)

fyne v2.5.0

go_tool_nm_v2.5.0.txt (5.3MB)

The size of the output is 2MB for v2.4.5 and 5.3MB for v2.5.0, a difference of more than 2*.

andydotxyz commented 2 weeks ago

Please compare the results of fyne package -release not go build as that applies the appropriate debug removal etc.

The reason this matters is that a change in dependencies can add more debug info without actually resulting in much difference in the compiled binary requirements. I think this may matter because the change is different across each platform. For example Android looks like 50% larger for debugging, or 28% in released mode. This makes sense as all the libraries required to do internationalisation do comprise a lot of code.

andydotxyz commented 2 weeks ago

One more point:

$ go build -o test $ du -h test 62M test

Please use ls and not du, as the latter can factor in your filesystem configuration to how much space is actually used. For a single binary file even it can make a difference, for example:

[develop] ><> ls -lh Fyne_Hello.apk                       
-rw-r--r--  1 andy  users    18M 20 Aug 12:41 Fyne_Hello.apk
[develop] ><> du -hs Fyne_Hello.apk                       
 19M    Fyne_Hello.apk

It looks like the baseline file size for a compiled executable to be released has gone from about 14MB to 18MB, but this is platform specific - around 27% increase (in development we measured it as under 1/3 so that is consistent).

Please check with the "hello world" app to eliminate the possibility of something relating to your app triggering bundled items.

This remains my biggest request of you, so we can see if the issue is with the environment or the project dependencies.