Reduce the binary size of ceresdb-server
Describe this problem
Now the compiled ceresdb-server's size has reached up to 1.3GB, which is unbelievable.
Steps to reproduce
Just compile the ceresdb-server and check its size.
Expected behavior
The binary size should not be so large.
Additional Information
The way to reduce the binary size that I can come up with now is to remove the unused dependencies, including:
- Replace protobuf with prost used by
protoscrate so to remove grpcio dependencies; - ...
Don't expect it's already exceed 1G. but after strip it, it's just 59M, so this issue may not very serious, at least for now.
$ ll -h target/release/ceresdb-server ~/bench/ceresdb-server
-rwxr-xr-x 1 chenxiang chenxiang 1.3G Oct 9 17:11 /home/chenxiang/bench/ceresdb-server
-rwxr-xr-x 2 chenxiang chenxiang 59M Oct 11 21:44 target/release/ceresdb-server
#322 reduce binary size to 500M, but at the cost of long build, we can introduce more profiles to balance size and speed.
- https://github.com/influxdata/influxdb_iox/blob/main/Cargo.toml#L117
IOx have a quick-release profile
strip removes debug info to reduce the binary size. Here is my release binary size without the release.profile.debug = true:
➜ ceresdb git:(main) ✗ ll -h target/release/
Permissions Size User Date Modified Name
drwxr-xr-x - ruihang 10 11 20:19 build
.rwxr-xr-x 61M ruihang 10 11 20:23 ceresdb-server
.rw-r--r-- 18k ruihang 10 11 20:23 ceresdb-server.d
drwxr-xr-x - ruihang 10 11 20:23 deps
drwxr-xr-x - ruihang 10 11 20:19 examples
drwxr-xr-x - ruihang 10 11 20:19 incremental
.rw-r--r-- 18k ruihang 10 11 20:23 libceresdb.d
.rw-r--r-- 17M ruihang 10 11 20:23 libceresdb.rlib
So the strip is not a feasible way, otherwise we can just eliminate it on building.
reduce binary size to 500M, but at the cost of long build
link unit and lto are not only the size reducing options. They may also have influence on performance. Maybe open them on every formal release is a better choice. (or lto = "full", might be even better)
So the strip is not a feasible way, otherwise we can just eliminate it on building.
It's true. Debug information is necessary for us to troubleshoot in prod env.
In #322, what matters most to reduce binary size is actually the option: opt-level = "z". However, this may cause performance degradation, and for this reason #322 has been reverted already.
It's true. Debug information is necessary for us to troubleshoot in prod env.
-Csplit-debuginfo just get stabilized in 1.65, so we may can rely on this to both reduce binary size and still have to ability to debugging.
- https://github.com/rust-lang/rust/pull/98051/