AllenDang / cimgui-go

Auto generated Go wrapper for Dear ImGui via cimgui
MIT License
332 stars 51 forks source link

Binary size #252

Open Wieku opened 7 months ago

Wieku commented 7 months ago

I'm migrating my code from https://github.com/inkyblackness/imgui-go (more specifically https://github.com/neclepsio/imgui-go I use as replacement) and was taken by surprise that release build (-s -w ldflags) of my program with cimgui-go now weights ~7.5MB more:

Debug build increased from 44.8MB to 61.8MB:

All built with go 1.21.0, gcc/g++ 12.2.0-msvcrt-posix-seh via winlibs.

I don't think implot and immarkdown adds so much so something else is happening but cgo/c/c++ ecosystem is a dark magic to me to figure out what.

gucio321 commented 1 week ago

@Wieku maybe its because we also use imnodes and imgui_markdown... anyway, consider the following:

[cimgui-go (0) ]$ du -hs  lib/linux/x64/*
6.8M    lib/linux/x64/cimgui.a
4.0K    lib/linux/x64/dummy.go
472K    lib/linux/x64/libglfw3.a
5.2M    lib/linux/x64/libSDL2.a

idk when (in "code history") this issue was opened, maybe your code include sdl unnecessarily?

Wieku commented 1 week ago

@gucio321 I will test over the weekend with a new version, but at the time I was building it with -tags "exclude_cimgui_glfw exclude_cimgui_sdli"

My theory is that because it links statically to the ".a" library it's not stripping unused symbols? IIRC inklyblackness' one is building imgui during the package build.

Wieku commented 1 week ago

@gucio321 I've ported the app to v1.0.0. I've done a symbol export via DLL Export Viewer and all imgui symbols are exported: exported-cimgui.txt

vs inky, which has only select functions exported: exported-inky.txt

So not stripping theory kinda makes sense I think?

I see ~600KB reduction in release build, which in reality is a bit bigger considering fresh build has new code and uses go 1.23.

Just for funzies I've ran goweight on v1.0.0, and there's some reduction, but still the size seems kinda excessive: image

gucio321 commented 1 week ago

sound reasonable. I'm a bit afraid to touch this C/C++ sructure in our project as it somehow works. but this would be something we might want to do in a future.