Hacker News new | ask | show | jobs
by pmoriarty 3137 days ago
What's the advantage of doing this over using cython or pypy?
2 comments

More perfs since you are going lower level. You are not limited by cython types or pypy git warming up. You can use the full range of c libs AND rust libs. You benefit from the cargo build tools.
I'm not sure how different this is with Cython since you can also write C/C++ code with it, and hence use any C/C++ libraries. I say that the benefit offered by the example is more of bringing the Rust ecosystem to Python than solving performance issues.
Well, with cython, either you write python compiled to C, and you won't match rust perf nor types, or you write c/c++ and bind it to python, and you won't match rust safetiness.
why would rust have better performance than cython? cython is as fast as C
Cython just transpiles to C. It's not "as fast as C", it's as fast as the runtime support structures it uses, and the communication with Python allows.
You can write very efficient Cython code but it's true that in this case, you tend to adopt a lower level code style that is very close to C/C++. Basically, you need to think about the C/C++ code that will be generated by Cython.

C/C++ compilers might be able to generate more optimized native code than what rutsc does though. Actually, this is a question: how good is rustc with numerical / math intensive code? For instance, does it implements loop unrolling and SIMD vectorization?

yes, exactly as I said.
Total layman here, but I thought one would use Rust because it’s easier to write “safe” code with it than C/C++, while maintaining an equivalent low-level speed advantage.
you should also quote "easier" ;)

it's certainly easier once you sacrifice a goat to the compiler to stop insulting you and your mother.

disclaimer: i love rust

Well it's better than your client insulting you and your mother because your software killed their goat by mistake.
lol. It's sad that I can only upvote this once :)
Cython is unsafe.
It's much easier to learn Cython once you know Python. That's the biggest selling point.
But the tooling is terrible in comparison. I find rust sigificantly easier as a python developer than cython. There is so much more rust ecosystem to take advantage of.
To be fair to Cython, they have access to the entire C++ stdlib, so that's a fairly good amount of tooling. The main thing is lacks is good documentation and memory safety.
And C++ has absolutely no package distribution system at this point.
Cython deceptively similar to Python with a lot of the pitfalls of C baked in. I personally found their documentation lacking and had to read through tons of Cython projects to discover how it behaved in many scenarios. I've had a much better experience with Rust documentation in comparison.