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-levelThreshold
0N/A, only inlines always-inline functions
1N/A, only inlines always-inline functions and LLVM lifetime intrinsics
2225
3275
s75
z25

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.

8 Likes

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.

3 Likes

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

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