4 ms·
On the other hand, Rust's borrow checker eliminates very many correct programs (unless using unsafe code...not sure if that counts or not). At a macro scale, I
by paulddraper 10y ago
On the other hand, Rust's borrow checker eliminates very many correct programs (unless using unsafe code...not sure if that counts or not).
At a macro scale, I have no doubts that Rust's benefits will win out. Understandable abstractions, fearless concurrency, etc. At a micro level, I would be surprised if some ugly, reprehensible C wasn't faster.
I think Rust's approach to systems programming is superior in many ways. I just won't be surprised if it loses a microbenchmark.
- codys 10y ago> eliminates very many correct programs While this is also true (there are certainly correct programs that aren't writable in rust without unsafe{}), in this context I'm guessing you mean "incorrect programs".
- paulddraper 10y agoI mean correct, as in "Rust compile-time checks prohibit creating some compiled programs that would correctly produce the desired result". Rice's theorem means that rustc must fail programs that actually don't have memory errors. The same is true of C; some ASM programs can't be transcribed in a way that pleases a C compiler.
- red75prime 10y agoBut it doesn't mean that rustc (or C) will fail to compile all programs, which implement given functionality.
- red75prime 10y agoI don't know what downvoters were thinking. So I'll take a blind shot at explaining. I didn't say that Rice's theorem wasn't true. I said that in this case it doesn't matter. If program fails to compile, you don't give up because of Rice's theorem, you modify program to make it compile. Will it make program less efficient? Who knows. There's no theorem about that. Most likely it will.
- adrianN 10y agoI theory, Rust's type system can provide hints to the optimizer, for example about pointer aliasing. This is currently not leveraged (LLVM isn't too good at this, and rustc internal optimizations on the intermediate language are still on the roadmap).
- eutectic 10y agoAny optimization that the Rust compiler might do can very likely be reproduced in C given sufficient time and effort.
- adrianN 10y agoI think you have to compare using equal programmer effort if you have two languages that in principle allow you to produce any instruction sequence you like. You don't see performance critical applications (the stuff supercomputers run for example) written in Assembly, even though in theory you might be able to squeeze out a little more performance when Fortran and a good compiler gets you almost as far for much less money.
- emn13 10y agoIn small programs like this, it might not even take a lot of effort. It's trivial to read a program like this and make a very good guess as to where bottlenecks are without even running it, let alone profiling it. That kind of simplicity gets lost quickly, however, when programs grow. Then again, I don't really believe that the optimization opportunities are likely to ever matter much. At least not at this level. Perhaps for much more complicated things, e.g. a kind of compile-time sql or string-matcher the greater safety and the symbolic nature of the macros will let programmers write libraries that practically reason about instructions you give them and choose optimal strategies where C would need to do so at run time or with unmaintainable and unusable macros, but if it's just aliasing and some threading gains - well, those aren't huge often, and where they are, C can use em unsafely too (and that's often quite doable too!). Safety and maintainability sound like more realistic selling points to me - it may never actually beat C in real-world performance; but it doesn't have to - it just needs to come close.