Skip to content
This repository has been archived by the owner on Nov 18, 2024. It is now read-only.

Reduce binary size #25

Closed
wants to merge 154 commits into from
Closed

Reduce binary size #25

wants to merge 154 commits into from

Conversation

PsiACE
Copy link

@PsiACE PsiACE commented Oct 5, 2021

for x86_64-unknown-linux-gnu

  • reduce ~90% size for release
  • reduce ~65% size for debug

Signed-off-by: Chojan Shang [email protected]

@PsiACE
Copy link
Author

PsiACE commented Oct 5, 2021

Normally, the size on macos is already very small and no additional work is required

@tisonkun
Copy link
Contributor

tisonkun commented Oct 5, 2021

Interesting. @PsiACE could you elaborate a bit with the underneath. I'm curious about how this works.

@PsiACE
Copy link
Author

PsiACE commented Oct 6, 2021

I will explain a little later

@huachaohuang
Copy link
Owner

This looks like magic to me, would like to know some details too :)

@tisonkun
Copy link
Contributor

@PsiACE @huachaohuang we're starting the normal development cycle and it seems this PR should be rebased onto master.

It's still interesting to know the underneath this trick works for we may want it now or later.

@huachaohuang
Copy link
Owner

The technique looks interesting to me. But maybe this is premature optimization. Maybe we can consider it when we have trouble with the binary size.

@PsiACE
Copy link
Author

PsiACE commented Oct 31, 2021

Sorry I'm late.

Rust generates an absolutely massive amount of debug info by default. One easy workaround is to compress the debug info sections, on Linux with a .cargo/config like the PR. See MaterializeInc/materialize#2691

--compress-debug-sections=zlib-gabi # instructs the linker to compress debug info, most of the redundant debug info can be well compressed

debug = 1 # ask Rust to generate less debug info for release builds, this is usually the right tradeoff for a release build.

Some other optimizations from a tutorial min-sized-rust . Please check for more information. It is worth mentioning that

codegen-units = 1 # allow for maximum size reduction optimizations, but it may increase the compilation time

After investigation, it hardly adds much to the compilation time. If necessary, the number of codegen-units can be set for the specific crate, like

arrow = { codegen-units = 4 }

@PsiACE
Copy link
Author

PsiACE commented Oct 31, 2021

Maybe we can consider it when we have trouble with the binary size.

If this project goes well, we'll need it soon. Whether you intend to provide the binary to users or use docker, 90% reduction in release size means only tens of megabytes of space are needed

@PsiACE PsiACE changed the base branch from demo-1 to main October 31, 2021 04:15
@PsiACE PsiACE closed this Oct 31, 2021
@PsiACE
Copy link
Author

PsiACE commented Oct 31, 2021

we're starting the normal development cycle and it seems this PR should be rebased onto master.

It conflicts with the main branch, if necessary, I will reopen a new PR

@huachaohuang
Copy link
Owner

@PsiACE thanks for your contribution and explanation, I suggest that we can evaluate this optimization when we have a large enough binary.

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

Successfully merging this pull request may close these issues.

5 participants