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

Reduce Size of Go Binary and DLL/SO Files #508

Closed
tongsean9807 opened this issue May 3, 2024 · 1 comment
Closed

Reduce Size of Go Binary and DLL/SO Files #508

tongsean9807 opened this issue May 3, 2024 · 1 comment

Comments

@tongsean9807
Copy link
Contributor

Problem Statement

This request aims to reduce the size of the Go binary (rpc-go.exe) and the associated DLL/SO files. By decreasing the file sizes, we can improve the user experience, especially for users working with corporate laptops that may have limited disk space and have plenty of IT installed applications.

Go Build with -ldflags "-w -s"

Compile with -ldflags="-w -s": Implementing this flag combination will strip debug and symbol table information from the binaries without affecting the functionality of rpc-go.exe. This will significantly reduce the size of the binaries while maintaining full functionality.

ldflags

The go build command allows the use of linker flags to modify the way the final binary is created. Two particularly useful flags for reducing binary size are:

-w: This flag omits the DWARF symbol table, effectively removing debugging information.
-s: This strips the symbol table and debug information from the binary.

More information:
The -w turns off DWARF debugging information: you will not be able to use gdb on the binary to look at specific functions or set breakpoints or get stack traces, because all the metadata gdb needs will not be included. You will also not be able to use other tools that depend on the information, like pprof profiling.

The -s turns off generation of the Go symbol table: you will not be able to use go tool nm to list the symbols in the binary. strip -s is like passing -s to -ldflags but it doesn't strip quite as much. go tool nm might still work after strip -s. I am not completely sure.

Before reduction
image

After reduction
image

Reference:

  1. https://www.codingexplorations.com/blog/reducing-binary-size-in-go-strip-unnecessary-data-with-ldflags-w-s#:~:text=The%20go%20build%20command%20allows,debug%20information%20from%20the%20binary.
  2. https://stackoverflow.com/questions/22267189/what-does-the-w-flag-mean-when-passed-in-via-the-ldflags-option-to-the-go-comman
@bwendlandt-intel
Copy link
Contributor

Hey! Thanks for the feedback. We actually already implement this for our Release artifacts. You can see the line here. As Mike replied in the PR, the areas modified in your PR are just part of our validation efforts. Starting with RPC-Go v2.26.0 in early February, we stopped including debug symbols as part of the Release artifacts. You'll see that our file sizes are roughly equal between your screenshot and the artifacts (~7mb).

Although, we do not currently release Library .dll/.so artifacts. That is something in our backlog that we want to tackle.

I will make a note to include these optional build flags in our documentation to give folks the choice if they manually opt to build the executable or library rather than use the tagged release artifacts. I'll tag this issue when updated.

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

2 participants