Which CPU is better for Rust compiling?

Hi, I want to update my CPU from a Ryzen 5 3600 to something more powerful. I think the best one would be a Ryzen 9 5950X, but I also want a good gaming CPU and spend less money. So I tend to use a Ryzen 7 5800X3D or a 9 5900X. The 5900X is the cheapest of the three.

The 5800X3D is the best gaming CPU, but how does it compare to the 5900X when compiling Rust projects? Does it benefit from the larger cache and is it comparable to the 5900X or are more cores always preferable?

You want to take a look at cargo build --timings to see how many crates are being built in parallel.

I believe standard Cargo.toml is to have 256 llvm codegen units, and I believe there is recent work on parallelizing parsing. However, seeing how many crates you have compiling concurrently will provide intuition on whether you can take advantage of multiple cores.

More cores should be better, but is more cache per core also better? Does the Rust compiler has any benefit of more cache per core? The 5800X3D has 12MB third level cache per core while the 5900X only has about 5MB. The 5950X is even worse with only 4MB.

--timings doesn't tell me if more cache has any benefit.

The rust compiler is basically a gigantic hash table benchmark, so does tend to care alot about cache.

One of the GamersNexus videos about the X3D chips said that they stopped running the clang benchmark because it was just a cache measure, and I wouldn't be surprised if rustc ended up similar.

6 Likes

Sites that benchmark CPUs often use Chromium's compilation time in their benchmarks. This is the closest workload to what Rust does (clang and rustc share LLVM backend) and will be the best indicator of how fast the CPU is for Rust.

I would expect more cores to be better. Cargo parallelizes builds, and even more parallelization is coming to the Rust compiler:

6 Likes

I decided to order a 5800X3D because I think that more threads don't scale linear. I don't know if the cache has a significant effect to compile time, but it has definitely an effect in games.

With the 5800X3D I have 8 cores and 16 threads. I think this will be enough for my projects.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.