The Rust Calling Convention We Deserve
2 days ago
- #Rust
- #Performance
- #ABI
- The article criticizes the C ABI for being inefficient in passing complex types and suggests the Go register ABI as a better alternative.
- Rust currently uses a conservative calling convention that mimics the C ABI, leading to suboptimal code generation for simple functions.
- The author proposes a new calling convention for Rust, `-Zcallconv=fast`, which would optimize argument passing by utilizing registers more effectively.
- The proposed calling convention involves complex heuristics for register allocation, including handling of structs, unions, and enums to maximize register usage.
- The article discusses the technical challenges of implementing such a calling convention in LLVM, including the need for function prologues and epilogues to handle register-based argument passing.
- The author suggests that Rust could leverage its ability to inspect function bodies to optimize ABIs further, such as by eliminating unused arguments or passing hot arguments in registers.
- The conclusion highlights the potential for significant performance improvements but acknowledges the complexity and expertise required to implement these changes in Rust's compiler.