netbird icon indicating copy to clipboard operation
netbird copied to clipboard

smaller executable for openwrt

Open JakubZukal opened this issue 1 year ago • 6 comments

Is your feature request related to a problem? Please describe. Hi. We are using Netbird on a Collie Router (GL-X300B) and cannot upgrade from version 0.25.3 (5.8M) to 0.27.* (9.8M) due to insufficient space on overlayfs:/overlay. Unfortunately, increasing the space might not be possible for us.

Describe the solution you'd like Smaller executable.

Describe alternatives you've considered I've tried to minify the executable, but it's still not enough.

dckr-build# GOARCH=mipsle GOOS=linux GOMIPS=softfloat go build -ldflags="-s -w" -o collie_netbird
dckr-build# ls -la collie_netbird
-rwxr-xr-x 1 root root 36241591 May 20 20:11 collie_netbird

dckr-build# mipsel-linux-gnu-strip collie_netbird
dckr-build# ls -la collie_netbird
-rwxr-xr-x 1 root root 36180352 May 20 20:11 collie_netbird

dckr-build# upx --best collie_netbird
-rwxr-xr-x 1 root root 9711584 May 20 20:11 collie_netbird

Additional context Nope.

Is there a way to further shrink the binary a little bit more?

JakubZukal avatar May 20 '24 20:05 JakubZukal

An interesting solution would be to use a different compiler for this, like tinygo. Unfortunately it doesn't work with MIPS arch. https://github.com/tinygo-org/tinygo/issues/1075

JaSei avatar Jun 06 '24 10:06 JaSei

Tinygo also doesn't support net/http/httptrace which is used by http2/grpc

lixmal avatar Jun 06 '24 11:06 lixmal

@JakubZukal can you check if the latest version has improved with UPX? we removed some dependencies that were adding 5MB in binary size since v0.27

mlsmaycon avatar Jun 25 '24 08:06 mlsmaycon

builder# GOARCH=mipsle GOOS=linux GOMIPS=softfloat go build -ldflags="-s -w" -o collie_netbird
builder# ls -la collie_netbird
-rwxr-xr-x 1 root root 29229239 Jun 25 08:12 collie_netbird

builder# mipsel-linux-gnu-strip collie_netbird
builder# ls -la collie_netbird
-rwxr-xr-x 1 root root 29215776 Jun 25 08:17 collie_netbird

builder# upx --best collie_netbird
builder# ls -la collie_netbird
-rwxr-xr-x 1 root root 8332280 Jun 25 08:17 collie_netbird

It is 14.2% smaller than my previous attempt. Great work! I'll try some other options to minify it a bit more, as I need it to be around 7 MB. I'll let you know ASAP.

JakubZukal avatar Jun 25 '24 08:06 JakubZukal

We have some work planned around replacing gopacket with an alternative, which should also reduce a few MBs.

This will take some time as we are introducing some significant relay changes

mlsmaycon avatar Jun 25 '24 08:06 mlsmaycon

Hi. JFYI, I was able to significantly minify the executable. I'm currently testing it on the gl-x300b, and it seems to be running just fine.

builder# GOMIPS=softfloat GOARCH=mips GOOS=linux CGO_ENABLED=0 go build -ldflags="-s -w -X github.com/netbirdio/netbird/version.version=v0.28.7" -gcflags="all=-l" -o netbird
builder# ls -la netbird
-rwxr-xr-x 1 root root 26017975 Aug 13 15:15 netbird

builder# upx --best --lzma netbird
builder# ls -la netbird
-rwxr-xr-x 1 root root 4692292 Aug 13 15:15 netbird

JakubZukal avatar Aug 13 '24 15:08 JakubZukal