3 ms·
Would there also be a performance boost compared to C code which properly uses 'restrict'?
by tpush 12y ago
Would there also be a performance boost compared to C code which properly uses 'restrict'?
- kibwen 12y agoThe underlying compiler backend would use the same alias optimization pass for both Rust and C. Rust's advantages here are that all Rust code is automatically eligible for such optimization without the programmer having to do any work at all, and whereas a programmer can get `restrict` usage wrong (or alternately fail to have the confidence that a given pointer is truly unaliasable), the Rust compiler has perfect information. To be fair, there are also optimizations that C can do that Rust can't, often resulting from C's undefined behavior.
- tpush 12y agoThanks for the information! Looking very much forward to rust 1.0.
- bjz_ 12y agoRust's type system enforces a great deal more invariants in terms of lifetimes, ownership and mutability than C, which enforces virtually nothing. This should therefore give the compiler far more room make optimizations without the fear of changing the semantics of the program. So in the future safe, idiomatic Rust code should be able approach the performance of highly optimized C code, without having to drop resort to unsafe code (note of course that C is implicitly unsafe).