Why does Rust generate 10x as much unoptimized assembly as GCC?

That's actually not the case:

-C inline-threshold

This option lets you set the default threshold for inlining a function. It takes an unsigned integer as a value. Inlining is based on a cost model, where a higher threshold will allow more inlining.

The default depends on the opt-level:

opt-level Threshold
0 N/A, only inlines always-inline functions
1 N/A, only inlines always-inline functions and LLVM lifetime intrinsics
2 225
3 275
s 75
z 25

Interestingly, setting a custom -C inline-threshold=0 still enables some inlining. I've seen some reasonable improvements in debug runtime speed in personal projects just by setting an inline threshold of 25.


I haven't looked at the implementation of the inlining cost function in llvm but that would make sense if less assembly instructions are emitted at the call site if the function is inlined. That could easily be the case for very small functions.


Note that in the case of cargo check the code isn't translated anyway, so the optimization level you set doesn't matter.