DEV Community

Discussion on: Performance Comparison, Rust vs Crystal with Redis

Collapse
 
tamas profile image
Tamás Szelei

Great comparison. What happens if you enable LTO in rust?

Collapse
 
jgaskins profile image
Jamie Gaskins

I'm not sure what that is. Is that the same as the --release flag?

Collapse
 
aidiakapi profile image
Aidiakapi

Add:

[profile.release]
lto = true

In Cargo.toml to enable it. It allows more optimizations between crates at the cost of longer compile time. Though it's unlikely to give a 2x improvement.

Thread Thread
 
tamas profile image
Tamás Szelei

Sorry, just saw your answer and after I practically typed the same. I agree that it's unlikely to give a 2x speedup.

Collapse
 
tamas profile image
Tamás Szelei

LTO stands for link-time optimization, which is a great feature of LLVM (thus, rustc). You can enable it in your Cargo.toml:

[profile.release]
lto = true

The above will make --release builds use "fat" LTO, meaning all dependencies and the project itself is link-time optimized (you could set it to "thin" which means LTO is only applied to the current crate).

Another option to go even further is PGO, but that is a bit more involved and I haven't tried it with rust. Here is some documentation if you are interested: doc.rust-lang.org/rustc/profile-gu...

Combining both can go pretty far in optimizing performance.