r/rust • • Nov 17 '22

What are Rust’s biggest weaknesses?

What would you say are Rust’s biggest weaknesses right now? And are they things that can be fixed in future versions do you think or is it something that could only be fixed by introducing a breaking change? Let’s say if you could create a Rust 2.0 and therefore not worry about backwards compatibility what would you do different.

220 Upvotes

390 comments sorted by

View all comments

Show parent comment

16

u/zesterer Nov 18 '22

With respect, we've almost never felt the need to reach for unsafe when writing r/Veloren, despite the game having pretty intense performance requirements nowadays.

The only occurrences of unsafe we have are related to the plugin API, something that needs to be unsafe because the compiler doesn't have the ability to understand the necessary invariants.

The idea that "unsafe = performance" is a myth. It's much more useful when building up abstractions or getting around limits in the compiler's ability to reason about invariants.

3

u/[deleted] Nov 18 '22

Doesn't mean that not using unsafe will cause your code to be slower than Python. What I meant is that unsafe can be an extra boost if you absolutely need it.

9

u/zesterer Nov 18 '22

But it's not, though.

It doesn't 'boost' anything, or change the rules of Rust: it just gives you permission to override some very specific overzealous checks the compiler performs provided you stick to the underlying rules that Rust requires.

I can't think of any code in Veloren that would be meaningfully faster with unsafe that isn't worthy of using a generic, well-maintained abstraction for (like rayon, say), and we have a lot of performance-critical code.

unsafe is far more useful for creating abstractions with new semantics, in my view. Internal mutability and reference-counting, for example. It is a good idea to detach 'performance' and 'unsafe' in the mind of the community, because they're entirely unrelated things. More often than not, claims that unsafe makes something 'faster' come down to the code either being unsound, or a developer being insufficiently motivated to create a semantic abstraction that enables the optimisation (but is not itself the optimisation).