Hacker News new | ask | show | jobs
by rnikander 1035 days ago
I still can't use C++20 modules with a macOS app (Clang). I tried, and compile times balloon 10-30x on some files.

Maybe I should give up and try Rust. Does Rust give you _maximum_ control over performance the way C and C++ do? I need that and that's I why I used C++ in the first place.

5 comments

> Does Rust give you _maximum_ control over performance the way C and C++ do?

Yes, with a small asterisk. In general, this is true. In practice, with the way optimizations go, sometimes one or the other may be faster. Or people playing with definitions. But the answer to your question in spirit is "yes."

>Does Rust give you _maximum_ control over performance the way C and C++ do?

In general yes.

What do you mean, exactly?

Rust doesn't have hidden things going on in your programs--and the culture is very much "if it's slow it should be visible in the source code".

It's hard to say what I mean exactly, because I don't know what I will need to make my program fast, but I know I want the ability to adapt and control low level details. That would include memory layout and allocation, and skipping potential safety checks if I can prove my code works, beyond what the type system and compiler can prove.

I had some Swift code a while back. It was optimized, but when I rewrote it in C++ it got a lot faster. Something bad was happening that wasn't "visible in the code", as you said. The code was pretty complex algorithm and data structure stuff related to computational geometry and computer graphics. I suspect if I tried it in Rust I'd be fighting with the borrow checker and that is not appealing.

Only if you dance around the baggage of the borrow checker and restructure your performant data-structures to use integer indices. Thats all how most Rust DS libs do this - get rid of references and replace them with integer pointers.
A side effect from Apple nowadays caring more about Swift than contributing to clang.

https://www.kitware.com/import-cmake-c20-modules/

I want to do cross platform native C++ dev. Maybe I should switch to Microsoft-land. I've been using a MacBook for years. I see Visual Studio docs talking about C++ cross-platform mobile (iOS, Android), but nothing about desktop (eg, Linux, macOS).

I suspect Visual Studio on Windows works better than what I've been using – VS Code or Emacs with clangd, which sometimes runs amok, takes 20GB of RAM, and kills my laptop.

It depends on what you mean by maximum performance. In general Rust is pretty fast, but safety checks do cause slow down, and even with the unsafe escape hatch there are code patterns and use cases Rust currently can't address that well.