Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binary files size #688

Open
homerestis opened this issue Oct 23, 2024 · 3 comments
Open

Binary files size #688

homerestis opened this issue Oct 23, 2024 · 3 comments

Comments

@homerestis
Copy link

OS: Arch linux. Compiler: dmd.

git clone --recursive https://github.com/buggins/dlangui.git
cd dlangui/examples/helloworld
dub build -b release

The size of the binary file is 12M. Isn't it too much for a helloworld? How can I reduce this size?

@FreeSlave
Copy link
Contributor

FreeSlave commented Oct 24, 2024

You can use strip on the binary to reduce its size (this should save around 4M)
Also try using ldc2 instead of dmd (ldc generally produces smaller binaries than dmd).

dub build -b release --compiler=ldc2

For me the stripped release binary built with ldc is 4,3M.

@homerestis
Copy link
Author

homerestis commented Oct 24, 2024

Thanks. Now the size is 4M.
I think it's because the ldc2 uses shared libraries:

ldd ./helloworld
	linux-vdso.so.1 (0x00007b5a72492000)
	libz.so.1 => /usr/lib/libz.so.1 (0x00007b5a72473000)
	libphobos2-ldc-shared.so.109 => /usr/lib/libphobos2-ldc-shared.so.109 (0x00007b5a71a00000)
	libdruntime-ldc-shared.so.109 => /usr/lib/libdruntime-ldc-shared.so.109 (0x00007b5a71ec3000)
	libm.so.6 => /usr/lib/libm.so.6 (0x00007b5a71911000)
	libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007b5a72445000)
	libc.so.6 => /usr/lib/libc.so.6 (0x00007b5a71720000)
	/lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007b5a72494000)

@GrimMaple
Copy link
Collaborator

I were about to suggest both using strip (honestly, it's very powerful), and using shared libraries. IIRC, dmd links in druntime and phobos in by default

4MB is fairly OK for a hello world, considering that it doesn't grow much afterwards :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants