6 ms·
All this is good stuff. I think soon should be a time to look at performance. Performance should be close to or better than C++ on average. We know about "the
by rdtsc 12y ago
All this is good stuff.
I think soon should be a time to look at performance. Performance should be close to or better than C++ on average. We know about "the root of all evil". But, if there is going to be any large uptake from those using C++ currently (and I imagine a lot of those developers are concerned about performance, memory usage etc), Rust simply has to compete on performance as well.
Go in a way started that path. The whole "systems language" re-interpretation and all. But it never quite became the systems systems language. It can't quite eat C's and C++'s lunch figuratively speaking.
Rust might be able to do it. But regardless of concurrency, type safety and other features if it cannot be fast enough it will have a hard time.
- steveklabnik 12y agoWe already do pay attention to performance. In general, Rust should already be in the same league as C or C++. Please open issues if you find something that isn't.
- kibwen 12y agoAnd even more important than current benchmark numbers is that the language is explicitly designed to be optimizable, and takes the idea of "zero-cost abstractions" seriously. I can count on two fingers the number of places where we impose dynamic checks by default in the name of safety, and one of those can be unsafely turned off and the other can be safely disabled with proper code structuring. (Theoretically we can also leverage Rust's ownership rules to automatically generate aliasing information. When implemented this should be an across-the-board speed boost for all Rust code in existence, in a way that C and C++ compilers can only dream of.)
- tpush 12y agoWould 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).
- hugh4life 12y agoI noticed that in the last round of the language shootout benchmarks that rust was significantly behind C++(and I also noticed that this was being addressed on the rust reddit). I'd like to see more benchmarking done between rust and C++ where there is a solution for each language that is idiomatic or safe while another solution optimizes for performance.
- steveklabnik 12y agoThere's a few reasons for this: 1. We haven't put in the time for the benchmarks game, because we're too busy working on the language. 2. IIRC, the C++ version uses GMP, and we don't, because licensing. You can install a package if you need GMP, but that doesn't work for the benchmarks game. > I'd like to see more benchmarking done between rust and C++ where there is a solution for each language that is idiomatic or safe while another solution optimizes for performance. Much of Rust's safety comes with no runtime overhead, but some of it does.
- igouy 12y ago> but that doesn't work for the benchmarks game. fyi http://benchmarksgame.alioth.debian.org/u64/program.php?test=pidigits&lang=rust&id=2 http://benchmarksgame.alioth.debian.org/u64/program.php?test...
- igouy 12y ago> You can install a package if you need GMP, but that doesn't work for the benchmarks game. Why doesn't that work for the benchmarks game? > Much of Rust's safety comes with no runtime overhead, but some of it does. I guess he'd like to find out how much overhead.
- bjz_ 12y ago> I think soon should be a time to look at performance. Performance should be close to or better than C++ on average. The language has been designed from the ground up to compete on this level. Also note that Rust potentially has far greater room for compile time optimizations than C and C++, because the compiler knows far more about lifetimes and ownerships. This can be seen in one of the last items in the release notes: > Stack usage has been optimized with LLVM lifetime annotations.
- acqq 12y agoI thought it won't be more than two times slower. The basic design was supposed to alow the speed of C with the added benefit of safety. But it's much worse: http://benchmarksgame.alioth.debian.org/u64/benchmark.php?test=all&lang=rust&lang2=gcc&data=u64 http://benchmarksgame.alioth.debian.org/u64/benchmark.php?te... I agree with you, unless the language creators address this the language has much more chance to remain unused.
- dbaupp 12y agoMost of the 'problems' there are Rust programs not micro-optimised to the ridiculous extent of the C ones, e.g. the C ones almost all use SIMD instrinsics or features like OpenMP. Rust is a new, experimental language and the support for SIMD is still in development, and we still don't have much in the way of data-parallel libraries. The type system has been expressly adjusted to allow for safe data-parallel libraries though, so they will appear. Also, a few other points: - Rust allows for opting in to unsafe code (with rules and overhead similar to C), which can be used for performance optimisations. Last time I checked, none of the Rust benchmark programs used any unsafe. (On the other hand, all of the C programs are effectively using `unsafe` code always) - C is using highly optimised libraries; Rust has zero overhead FFI, and so can easily call into them, but is not for those benchmark (e.g. the pidigits one is just a benchmark of "are you using GMP?", if the Rust was written to use it, there is no reason it would be slower than C) - The worst offender (reverse-complement) is apparently written without any thought of performance, e.g. it is doing formatted IO for each and every character it emits, rather than writing to an in-memory buffer and dumping that in one go like the C. In summary, those benchmarks do not reflect the fundamental speeds of the languages, other than the suboptimal SIMD support in Rust.
- acqq 12y agoImprove the benchmarks and submit them to the shutout. Use the benchmarks during the development too to remain focused on the performace. It's not helpful when somebody in the small circle knows that the benchmark can be implemented better if there aren't any reference examples. I believe Servo is your reference, but you definitely need to have a bit wider horizons than that. The small benchmarks are good representation of the rest of the world. And the good advertisement, once they are fast. Please don't ignore them.