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

(exa PR) 1160: Update Cargo.toml to optimise binaries for size #23

Merged
merged 3 commits into from
Jul 29, 2023

Conversation

cafkafk
Copy link
Member

@cafkafk cafkafk commented Jul 29, 2023

Strip binaries, change optimisation level to heavily optimise for size, change codegen units to 1, which slows compile times but adds maximum size optimisations.
@cafkafk cafkafk changed the title (exa PR) 1160 (exa PR) 1160: Update Cargo.toml to optimise binaries for size Jul 29, 2023
@cafkafk cafkafk added enhancement New feature or request help wanted Extra attention is needed needs feedback labels Jul 29, 2023
@cafkafk
Copy link
Member Author

cafkafk commented Jul 29, 2023

This looks obviously correct, but opinionated. What do you think @sbatial ?

Specially codegen-units = 1 is interesting, because while it would definitely be preferred for e.g. release binaries it would add a long build time for people compiling from source. I'm not for or against, but I'm not sure what the best option is.

@cafkafk cafkafk requested a review from sbatial July 29, 2023 11:06
@sbatial
Copy link
Collaborator

sbatial commented Jul 29, 2023

I've ran the possible combinations and I'd say strip = true would be sufficient.

lto = true strip = true opt-level = "z" codegen-units = 1 size in MB
x x x 1.2
x x x x 1.2
x x 1.5
x x x 1.5
x x 3.3
x x x 3.3
x 3.6
x x 3.6

Because I didn't know what to make of the opt-levels and the cargo documentation specifically says

It is recommended to experiment with different levels to find the right balance for your project.

I did do just that:

lto = true strip = true opt-level size in MB
x x 0 3.0
x x 1 1.6
x x 2 1.4
x x 3 1.5
x x s 1.2
x x z 1.5

With the opt-levels being:

  • 0: no optimizations
  • 1: basic optimizations
  • 2: some optimizations
  • 3: all optimizations
  • "s": optimize for binary size
  • "z": optimize for binary size, but also turn off loop vectorization.

(once again from the cargo book section linked above)

What is vectorization? I have no clue either, but apparently it is optimizing for modern CPU architectures by/and using some level of parallelization for loops: https://en.wikipedia.org/wiki/Automatic_vectorization

So my final verdict:

  • strip: ✔️
  • opt-level: "s" or "z", i don't really care. Let's just go with "s" and see if there are any problems
  • codegen-units = 1 ❌

Copy link
Collaborator

@sbatial sbatial left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comment

Cargo.toml Outdated Show resolved Hide resolved
cafkafk and others added 2 commits July 29, 2023 14:17
see: #23 (comment)

Co-authored-by: sbatial <mail@kbode.com>
Signed-off-by: Christina Sørensen <christina@cafkafk.com>
Copy link
Collaborator

@sbatial sbatial left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@cafkafk cafkafk merged commit 5ab9e4f into main Jul 29, 2023
@sbatial
Copy link
Collaborator

sbatial commented Jul 29, 2023

Forgot to mention: strip needs nightly cargo

@sbatial sbatial deleted the pr-1160 branch July 30, 2023 02:13
@sbatial sbatial mentioned this pull request Jul 30, 2023
63 tasks
Omnikron13 pushed a commit to Omnikron13/eza that referenced this pull request Mar 17, 2024
see: eza-community#23 (comment)

Co-authored-by: sbatial <mail@kbode.com>
Signed-off-by: Christina Sørensen <christina@cafkafk.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed needs feedback
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants