Making Rust faster than C
Supporters & funders
Rust, being a systems language, should be best in class for performance-sensitive software.
While the performance difference with C is small, it currently blocks performance-sensitive Rust implementations from being widely adopted. Why go through a challenging migration only to end up with a 1% performance drop or a 2% additional battery drain?
Our mission is to make critical infrastructure software safer. We must eliminate performance considerations as a barrier for adopting Rust in order to achieve this goal. This initiative exists to contribute to change, to change Rust's performance story with the ultimate goal of making it faster than C.
What we've done
Our work on zlib-rs put us on the path to improving the performance of state machines. Complex state machines are niche but foundational to many programs, such as parsers, interpreters, and networking protocols.
This work has resulted in a #[loop_match] language experiment. This language experiment achieves a 2.7X speedup on some parsers, and a 7% speedup in a zlib-rs benchmark. Exact numbers are here, and a blog post explaining loop-match is here.
Work plan
Work is in progress, see our workplan for details.
The work includes:
- the 2025H1 Rust Project Goal, "improved state machine codegen", and
- the 2026 Rust Project Goal "Explicit tail calls & loop_match"
We're seeking funding for the tail calls project goal (Milestone 3 in the workplan). Please get in touch with us, if you are interested in financially supporting our effort.
Acknowledgements
We want to acknowledge the work done in the Zig ecosystem where our idea was taken from fairly directly, and thank joshtriplett, jackh726 and folks at the codegen unconf at GOSIM 2024 for providing feedback.
We also thank Tweede golf for supporting the initial effort, and NLnet and AWS for funding the milestone 1, State machine codegen, and milestone 2, Identify performance bottlenecks.
What's next
The current initial work shows that there is room for improvement. While outperforming C is impossible in general, improving the performance of foundational systems libraries written in Rust furthers adoption, and hence the spreading of Rust's advantages like memory safety and portability. We believe the gap with C can be closed if we can better use Rust's advantages over C, e.g., having more information about the program that can be used to optimize.
In the next phase, a coordinated effort is needed to make Rust faster than C. We by no means think that we can do this alone. While a considerable effort, initial investigation indicates this a realistic goal and one where the expected effort is relatively small in comparison to the impact of the outcome.
For this next phase we are seeking funding. Are you interested in supporting our effort to make Rust faster? Contact us via rustfasterthanc@trifectatech.org.
Links
- RFC 3720
- improved state machine codegen project goal
#[loop_match]language experiment
Blog and news
-
Rust should have stable tail calls
Tail calls in Rust have been talked about for a long time, but especially from the outside it looks like very little progress has been made. Let's change that!
Read more ... -
Fixing our own problems in the Rust compiler
In our data compression projects, we use Rust where C is traditionally used. During the work, we've hit limitations in Rust itself and in the surrounding tooling. Over the years, we've become increasingly comfortable with fixing these issues ourselves.
Read more ... -
Improving state machine code generation
Over the past couple of months, Björn and I have been working on improving state machine code generation in the rust compiler, a rust project goal for 2025H1. In late June, PR 138780 was merged, which adds #![feature(loop_match)].
Read more ...