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

303

u/[deleted] Nov 17 '22
  • compile times. Fixable: no, only improvable.
  • learning curve. Fixable: no, only improvable.

There is actually a wishlist for rust 2.0 somewhere on github, it's pretty interesting

99

u/pluots0 Nov 17 '22

Are you familiar with the WIP cranelift backend? It is supposed to improve compile times to the point that I would consider them “fixed”

I think the general idea is that rust will start having the cranelift backend be the default debug choice, since it’s going to be much faster but can’t do heavy optimizations. Then use the standard LLVM backend (or new GCC backend) for release mode

127

u/[deleted] Nov 17 '22

I'm actually going to work on cranelift for my bachelor thesis next semester and I'm super stoked 😃

That being said, rustc will still be doing the same amount of work to product CLIF instead of LLVM IR. rustc does a lot and that's why we love it. Many techniques considered idiomatic in Rust put a lot of pressure on the compiler - compile time generics with monomorphization, deeply nested generic type signatures to tickle as many compile time guarantees out of the type system as possible... I think many of these things cannot be "solved" but represent a tradeoff and value judgement the Rust community has made and continues to make. I personally love those values, so I don't complain about the compile times!

19

u/pluots0 Nov 17 '22

That’s awesome! Hopefully you can figure out some great and speedy optimizations for the project.

Yeah, it can’t solve everything, but it still seems like build times generally are improved by 20-30% which is still massive.

6

u/robin-m Nov 18 '22

Awesome!

I think that looking on the other side of the zig fence is valuable. They plan to be able to recompile a single function and hotpatch it into a binary, allowing sub-1s of incremental rebuild, even when working with codebase with milions lines of code.

→ More replies (6)

10

u/nikivi Nov 17 '22

Anything you lose from using Cranelift for debug builds already or its not yet ready?

14

u/pluots0 Nov 17 '22

To my understanding it works and isn’t far from primetime, but may still be quite buggy just because it’s new.

If you’re up for it, trying it out isn’t all that bad. You need to clone & build the repo or get the artifacts from the repo’s GitHub actions, then you can use it directly like cargo. Link to the instructions: https://github.com/bjorn3/rustc_codegen_cranelift#usage

→ More replies (2)

28

u/azure_i Nov 17 '22

the learning curve is the real headache, because it makes it much more difficult to convince other people to try it. So even if you want to use Rust, you are stuck trying to get other people in your team and org to go along with it too and a lot of people dont want to or dont care to invest so much time learning it

19

u/mindmaster064 Nov 18 '22

The learning curve isn't bad if you were doing secure/bug free programming in the first place. Rust just forces you to do what you were supposed to be doing. Many things are actually easier or better in Rust - like the zero-cost abstractions, iterators, and so on. They just work totally better than other languages, and I mean 100% better. The thing is if you're a shitty programmer then Rust will wreck you mercilessly at the compiler and torment you for days before you really get anything up and working. You'll probably figure it out in a few days of grinding through the documents, but few people lack the patience and just want to be able to slap anything they code into the compiler and let it run. Your worst colleagues will be the ones constantly struggling with the compiler and Rust will automatically remind them of their position on the food chain.

If your team is not using OOP at all then moving to Rust is just an insurance policy not a paradigm shift. The payday will be when you can jettison garbage collectors and get half your memory back. (God, the GC in so many languages is so terribly bloating...) If you need it fast, safe, and correct then Rust is still the best language on the planet. Nothing will do what it will do, nothing... Other languages are not even close. The only language that is even SLIGHTLY close is C and you take pain with that. Once you use C then you have a lot of other problems like: "How do I implement collections?", "How are we handling errors?", "What is thread safe?", etc... You are going to spend just as more time figuring that out than you would have replacing your knowledge of C with Rust. C does this all with a 'hidden cost', but still requires the same standards to be held as Rust applies to your code intrinsically. It's not a savings to use the other language, it's just a potential error because it relies on the programmers understanding of these concepts rather than applying some sort of consistent paradigm. Many might look at that as more work (using Rust), but I look at as, "I do not have to wonder if the other people working on my project are doing things in the same secure way as I am." That is a constant problem in other languages. More time is spent enforcing the security and stability of C code than programming it.

The caveat being some ideas are just not implemented in Rust yet and may or not be ever because they can't. C doesn't care if you want to abuse it and make it do bad things. In Rust, you have to put things in unsafe blocks or access the low level parts of the std library to get to break anything. You have to be intentionally trying to break them, and it's obvious that when you are doing something glitchy the 'unsafe' blocks all over the place tell other people you are breaking the envelope and to apply extra scrutiny these sections of code. Just because Rust does this a lot of problems are immediately averted. In other languages, there is nothing flagging the code inside the code itself that you are doing something like this and unless someone is familiar with what you're doing they probably don't even understand that you're in this territory. Write that code in C or C++, come back in a year, and hand it to someone else to read. Do they still know you are doing the glitchy/low-level thing? Not a problem in Rust, it's in the unsafe block and everyone knows you are doing something special.

Most of the savings of the Rust is not your time as a programmer it will probably take more time to code anything in Rust. But, that time you've spent won't be spent on bug fixing crap that works. That's the trade, and it's a big one. The most prolific developers probably spend only 10-20% of their time writing new code. That is the real problem Rust is trying to fix - it allows you to get back the bulk of that 80% and make it more like 20% bugs, 80% new development... That's why you use Rust. There is no other real reason. (C can do everything Rust does, but without that advantage.)

12

u/anengineerandacat Nov 18 '22

The thing is if you're a shitty programmer then Rust will wreck you mercilessly at the compiler and torment you for days before you really get anything up and working.

Or you are literally coming from a language where lifetime management is automated and isn't your problem.

Has nothing to do with being a shitty programmer and more about willing to learn and gain mastery over the subject.

I can somewhat understand if someone who spent 13-14 years on C/C++ or C# went "Fuck that" to Rust; lifetime management is pretty massive overhead when you need to constantly think about it.

It's like grabbing someone who has been driving an automatic vehicle all their life and suddenly putting them into a manual; they are going to struggle and some may even hate the experience because the pro's don't outweigh the con's. This doesn't make them a bad driver.

4

u/buyIdris666 Nov 20 '22

Manual lifetime management is also slower than GC in many cases.

If your object is nested, has cycles, or a linked list, a good GC like Java's new ones will clean up memory without pausing your main thread while everything gets dropped.

A lot of rust devs reach for arena collectors and ref counting when dealing with complex objects. Those are both just shitty forms of GC.

7

u/aikii Nov 18 '22

I mean you're right but the length of the answer is meme material

→ More replies (2)

5

u/buyIdris666 Nov 20 '22

Meh this is a bit too rosy. Rust is the best language in the world for low-level work. If performance is not top priority Java is usually a better choice.

All the memory guarantees Rust gives you with zero of the lifetime management, runtime code generation, fast reflection, amazing runtime monitoring, and far faster compile times.

And the new Java GC's can do 300 microsecond collection so pause times usually don't matter.

→ More replies (3)

18

u/mindmaster064 Nov 18 '22

The two most important things to do in Rust:

  1. Make sure you are linking with lld (edit ~/.cargo/config)
  2. use the 'cargo build --jobs $(nproc)' to use all your cores.

Those two things alone will make your build time go about 20x faster. By default, Rust does the linking with whatever the 'cc' compiler is on your machine and probably will only use a single thread/core.

You can also put this same content either in #1 or your Cargo.toml file:

[target.x86_64-pc-windows-msvc]
rustflags = ["-C", "link-arg=-fuse-ld=lld"]

[target.x86_64-pc-windows-gnu]
rustflags = ["-C", "link-arg=-fuse-ld=lld"]

[target.x86_64-unknown-linux-gnu]
rustflags = ["-C", "linker=clang", "-C", "link-arg=-fuse-ld=lld"]

You only need the relevant line and some iteration of lld installed (a clang complete install would have it, but some distros like Ubuntu let you install it by itself.) You only need the relevant targets here that match your architecture on the machine you're building on/for. You can ignore the rest. Personally, I just use the config file setup rather than doing it for every single project.

13

u/rvdomburg cpal Nov 18 '22

use the 'cargo build --jobs $(nproc)' to use all your cores.

Doesn't cargo do that by default? https://doc.rust-lang.org/cargo/reference/config.html seems to say so.

→ More replies (1)
→ More replies (6)

11

u/armchair-progamer Nov 18 '22

verboseness. Fixable: no, only improvable.

Most people think of Rust as the opposite of verbose, and it's true that Rust is very terse for what it tries to accomplish: a safe, efficient language. But the fact that you need to explicitly specify lifetimes and trait objects and cloning, there is no GC and not everything is a dynamic pointer, means you will never be able to write code as terse and easily as you could in say, C# or Python

6

u/[deleted] Nov 18 '22

Personally I think the quest to save a few characters here or there when writing code has ruined the readability as well as the ease of building parsers/tooling (due to optional syntax) for so many languages it really isn't worth trying to go that way.

→ More replies (2)

14

u/slashgrin rangemap Nov 17 '22

I'm convinced that there are things that could be done about compile times that would radically improve the situation for many real world use cases, even if "straight line cold build" can't be improved much.

I'm mostly thinking of things like first class sccache integration, or something like it, with support for an active mode for sending compilation jobs to a build farm. This could help enormously for teams working on the same code bases.

For my own use, I have some shell scripts that let me work on my crappy old laptop as a thin-ish client and use my powerful desktop PC as a builder, and then end up with the final binary ready to run on my laptop. (Kinda like cargo-remote.)

I also wonder, as rustc moves to a more query-based compilation model, whether the problem of feature flags making it hard to share pre-compiled artifacts might be mitigated. E.g. if the compiler could emit a shareable blob of compilation "answers" that another instance of the compiler could use, maybe it could just ignore the bits that are irrelevant because they were affected by the active features. Or you could even run it in a mode that produces an "answers" blob containing code for several different combinations of features.

I guess to summarise what I'd be most excited about, it's solutions that let me bypass compiling things locally at all in many cases rather than just speeding up rustc.

→ More replies (1)

45

u/pickyaxe Nov 17 '22

I personally think the Rust learning curve is highly exaggerated, at least for the features most people would have a use for.

60

u/kukiric Nov 17 '22 edited Nov 17 '22

Lifetimes are a pretty big hump for newcomers and IMO not exaggerated at all. One of my friends almost dropped a project after several days of hitting his head against the wall trying to use mutable state in an async callback, which is trivial in garbage collected languages.

6

u/not_a_weirdoo Nov 17 '22

I tried to use an async callback with an internal state without having to put it in a box and pin it, finally gave up and use a struct with an associated async function instead 😄

→ More replies (5)

9

u/JarWarren1 Nov 17 '22

I think the learning curve varies greatly depending on which languages you already know.

If I hadn’t already been very comfortable in C I think I would’ve really struggled with rust

→ More replies (25)