this post was submitted on 17 Jul 2024
33 points (97.1% liked)

Rust

5744 readers
89 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

[email protected]

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 1 year ago
MODERATORS
top 4 comments
sorted by: hot top controversial new old
[–] [email protected] 11 points 1 month ago (1 children)

Welcome.

[profile.release]
opt-level = 'z'     # Optimize for size

It doesn't matter here, let's get that out of the way.

But I'm wondering if someone/someplace is wrongly recommending this!

Because lately I've been seeing this getting set in projects where their binaries wouldn't be typically running on environments where this is required or even helpful.

My concern is that some developers are setting this without really understanding what -Oz actually does.

[–] [email protected] 19 points 1 month ago* (last edited 1 month ago) (1 children)

This comment would be much better if it featured an explanation of your concerns with that particular opt setting.

[–] [email protected] 8 points 1 month ago

There is no deep explanation or anything.

Release profile defaults to -O3. -Oz compromises runtime performance for binary size.

When you start seeing for example network services which are not going to be running in constrained environments, nor do they restrict themselves from using heap allocations and all, when you see them set -Oz in their release profiles. Then you start to see small beginner projects setting it like OP here. You start to wonder if it's a pattern, and the settings are being copied from somewhere else, with potential misconceptions like thinking it can meaningfully reduce runtime memory usage or something.

I actually think I found the culprit, thanks to one of the projects I was hinting at mentioning it:

https://github.com/johnthagen/min-sized-rust

Looks like we have a second wave of net-negative common wisdom in the ecosystem, the first being optimizing for dependencies' compile times. But this one is not nearly as bad, as it doesn't affect libraries.

[–] [email protected] 1 points 1 month ago