-
Notifications
You must be signed in to change notification settings - Fork 124
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
Optimize file size of release binaries #571
Comments
BTW, looking through the binary with
and
there are lots more errors too... also seems to be way too much build log text embedded in a static binary... perhaps 50-100KB unnecessarily... |
This resource may be useful? |
Is https://github.com/google/bloaty useful to analyse this? |
Yeah, the Rust compiler by default adds some mostly unnecessary fluff to the release binaries it produces. Not generating PIE is a little-known trick I've seen greatly reduce the size of ELF (Linux, MacOS) executables without compromising runtime properties other than potentially making ASLR harder. That said, the In particular, as you saw with Also, I'd try to avoid using UPX on a project like OxiPNG because, in addition to the reasons you mentioned, the runtime decompression it requires prevents the operating system from sharing executable code memory pages among multiple OxiPNG processes, which is less efficient overall in cases where users are running OxiPNG concurrently. It also requires a small amount of time and in-memory scratch space for initial decompression, which has a negative impact on latency. |
Thanks @AlexTMjugador. Will you have time to experiment with this? |
I followed that link you provided and ran some experiments on macOS x86_64, including execution times for some:
Note the last line is without zopfli, parallel, or filetime features. We definitely wouldn't want to change the default Output from cargo-bloat:
|
If we want to seriously save space by changing |
Thanks @andrews05 for testing! I don't suggest any changes that reduce performance, just trying to eliminate the low-hanging fluff.
I presume the default level is
For releases, is the extra compile time on GH's infrastructure an issue? It also seems Lots of great stuff. Seems a binary < 900 KiB is achievable. |
I did try this but it seemed to give identical output. Maybe I was missing something... @ace-dent Default opt-level for release is 3, which is the highest performance level. PGO could indeed provide further improvements, it's not something I've looked into. |
Ah, found build-std was building to a different path. I've updated my post above to show further savings from that. @ace-dent Is there a particular target size you're hoping to achieve? We might be able to do a couple of these things by default, but some are a bit unorthodox, requiring use of unstable build tools and parameters. I would suggest if size is particularly important, users can build it themselves according to their needs. |
@andrews05 - Thanks for all your work on this.
Great to know. I feel we should keep the current speed optimization
While 800 KiB still seems relatively big, it appears to be reasonable. Is there any issues with:
If you check the optimized binary with
Agreed (for more extreme options). For my use case, I might remove parallel processing, etc. But we should make a good effort for Release builds. |
This PR makes 3 changes that together reduce binary size by around 25%: - Sets lto="fat" in cargo.toml - Sets panic="abort" in cargo.toml - Sets location-detail=none in RUSTFLAGS Closes #571 An unrelated change: I've replaced the zopfli test file with a smaller one that runs much faster, as well as removing the slow test for issue-133 which was related to an older alpha optimisation that is no longer relevant.
Feature Request / Minor –
The w32 executable binary is ~1,385 KB. While this seems small by contemporary standards, it is far larger than equivalent programs. e.g.
optipng
is ~ 209 KB (~15% the size).This is relevant when working with certain environments / VM's, as it's convenient to package multiple tools in a 'floppy' image <1.44MB.
UPX compression reduces the binary by a third(!) to ~462KB but should be avoided due to false positives with anti-virus software.
Standard zip compression also achieves a similar result ~610KB. This suggests there is a reasonable amount of redundancy in the binary.
@AlexTMjugador - is it possible to look at compiler optimizations that don't (signficantly) affect speed but produce a more compact executable? Perhaps there is extra fluff that is unneeded for Windows?
The text was updated successfully, but these errors were encountered: