To write faster code as the compiler devs

Two sufficiently common ways used to improve rustc performance is to box large enum variants (and leave the others as values). To help spot such situations Rust has -W variant-size-differences. Another used strategy is visible here:

Sometimes you extract a cold sub-function and you use #[inline(never)]. In other cases you extract a monomorphic part of a generic code (but in this #73912 example it's used #[inline]).

Stroustrup has written about an idea that may be useful to reduce the templates-induced bloat:

I think it could be nice to further study how people improve the performance of rustc, to help Rust uses perform similar optimizations in their code.

2 Likes

You're in luck! Someone has been chronicling their efforts to speed up rust:

https://blog.mozilla.org/nnethercote/2020/04/24/how-to-speed-up-the-rust-compiler-in-2020/

It's actually a series of posts.

1 Like

My point was: how can future Rust/rustc/Clippy design help Rust users improve the performance of their code in ways similar to rustc devs do?

1 Like

Some of those changes are for general performance (rustc handles the equivalent data in a faster way) but the mentioned issue of generics is mostly about speeding up the compiler by having less work to do (rustc has less data to handle, less monomorphic code in this case) to compile.
So they are different kinds of speed-ups for rustc, and it seems the former we can transfer and apply to application performance and the latter to application compile time.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.