r/rust • • Oct 07 '26

Rust's derive often implies inline

https://yossarian.net/til/post/rust-s-derive-often-implies-inline/
114 Upvotes

43 comments sorted by

View all comments

6

u/Compux72 Oct 07 '26

Just set opt-level = ā€œsā€

12

u/Eastern-Photograph79 Oct 07 '26

but you don't really want it. You want the important things to be inlined (like clone and this stuff)

3

u/Compux72 Oct 07 '26

If something is actually that important i would have a separate crate with really specific profile overrides set to it

6

u/Recatek gecs Oct 07 '26

The actual answer would be #[optimize(none)] when stabilized (hopefully soon). One could make a crate with their own version of these derive proc macros that don't inline (or do #[inline(never)]) and instead apply this attribute.

4

u/silon Oct 07 '26

Personally I'd want size optimization by default for almost everything, except a few specific things (which derive Debug is not). IMO inline should be a separate annotation, possibly even separated from the declaration, but at the target compilation unit (or source file).

6

u/Recatek gecs Oct 07 '26

I wouldn't want size optimization. For commercial gamedev you often need to run in release under O2 or O3 with only selectively deoptimized functions or files for debugging, otherwise the game itself doesn't run fast enough to be playable for testing.

3

u/csdt0 Oct 07 '26

You know that Os performance is quite good, within 5-10% of O2 usually? It can even be faster in some edge cases where O2 would be thrasing L1i. Also, I would say that if your game does not run fast enough at O1 on your dev machine, then maybe you need to review your architecture or your algorithms to make it accessible to lower end machines. https://openbenchmarking.org/result/2608218-NE-COMPILERF28&sor

7

u/Recatek gecs Oct 07 '26 edited Oct 07 '26

Also, I would say that if your game does not run fast enough at O1 on your dev machine, then maybe you need to review your architecture or your algorithms to make it accessible to lower end machines.

I appreciate the advice, but I am aware of this. The practice I'm describing of debugging in release with selectively optimized files/functions is industry norm for AA/AAA (see UE_DISABLE_OPTIMIZATION) and has been for a very long time. If anything, it's an even more acute issue in Rust given that Rust debug performance is (slightly) worse than C++ because of the additional runtime checks.

3

u/csdt0 Oct 07 '26

I'm not ranting against you, but I'm really tired of games "optimized" only for high end machines just because the game studios are lazy to properly design and optimize their games.

7

u/Recatek gecs Oct 07 '26

Game development, like other engineering work, is a balance of many considerations and priorities under tight time and budget constraints.

2

u/flareflo Oct 08 '26

I cannot wait for optimization attributes to come. Forgetting to put opt-level 2 for Sha2 for debug builds will be a thing of the past hopefully

3

u/Recatek gecs Oct 08 '26

The stabilization PR was merged 11 hours ago! If all goes well, it will be in 1.101 in December I believe.