Live data from Hacker News

What part of Rust compilation is the bottleneck?

kobzol.github.io

21–30 of 62 posts

Re: What part of Rust compilation is the bottleneck?

#21

One reason for me moving from Rust to Go was compilation speed. Go is a simpler language, so apples to oranges, but Go compiles so fast, which to me makes development very different.

second that. also another point: I write most Go code using only the stdlib, so there is no dependency web to take care on top of the actual code.

I also have much less dependencies with Go compared to other languages, especially in TS.

Re: What part of Rust compilation is the bottleneck?

#22

Over the years compile speed improved quite a bit (recently this: https://blog.rust-lang.org/2023/11/09/parallel-rustc.html made quite the difference) If we can squeeze more performance that's great but the largest concern I have around compilation is with the size of the target directory It can balloon up to node_modules levels

I don’t find node_modules exceeding even a few hundred megabytes very often. But Rust target directories can easily reach multiple gigabytes.

Re: What part of Rust compilation is the bottleneck?

#23
post #9

Earlier quoted context omitted.

That is definitely true, but from the article it's the backend that takes time, not the frontend where the language itself resides. If you compile go from llvm, it maybe as long as rust.

It’s not just Rust. Practically every compiler based on LLVM is slow. Swift, Zig, Clang. The Go compiler being written from scratch based on the Plan9 C compiler is a huge advantage.

Zig is moving away from LLVM. Its already has its own backend targeting debug builds for x86 and arm. ReleaseFast and ReleaseSmall is an entire different beast, but its going to be tackled eventually.

Re: What part of Rust compilation is the bottleneck?

#24
Monomorphization.

For every generic function f, rustc will generate as many instances as there are type instances (shape instances? Does the Compiler distinguish between different kinds of references that all get compiled to pointers?).

This feature has a cost. Compare to OCaml's uniform object representation that enables comparatively blazing compilation performance but pays a prize in performance and weird FFI restrictions (integers with a tag bit).

Btw. It's misleading to say "it's the backend" when the frontend is responsible for creating so much work for it.

Re: What part of Rust compilation is the bottleneck?

#25
post #24

Monomorphization. For every generic function f, rustc will generate as many instances as there are type instances (shape instances? Does the Compiler distinguish between different kinds of references that all get compiled to pointers?). This feature has a cost. Compare to OCaml's uniform object representation that enables comparatively blazing compilation performance but pays a prize in performance and weird FFI rest…

May I take the opportunity to ask, what’s the reason for Metas somewhat heavy use of Ocaml? What’s the appeal? You already pointed out the insane compilation perf.

Re: What part of Rust compilation is the bottleneck?

#26
post #24

Monomorphization. For every generic function f, rustc will generate as many instances as there are type instances (shape instances? Does the Compiler distinguish between different kinds of references that all get compiled to pointers?). This feature has a cost. Compare to OCaml's uniform object representation that enables comparatively blazing compilation performance but pays a prize in performance and weird FFI rest…

Kind of, despite its slow builds fame, it is possible to have relative fast builds in C++ with monomorphization.

By using binary libraries, external templates for common type sets, incremental compilation and linking, and nowadays (at least for VC++ already) modules.

What Rust still lacks is having sound alternatives to LLVM, or someone supporting similar workflows in Rust.

Using OCaml as an example, it is great to have multiple backends in the box, plus an interpreter, and pick and choose during development workflows.

Re: What part of Rust compilation is the bottleneck?

#27

One reason for me moving from Rust to Go was compilation speed. Go is a simpler language, so apples to oranges, but Go compiles so fast, which to me makes development very different.

OCaml compiles just as fast without having to compromise on the type system.

Re: What part of Rust compilation is the bottleneck?

#28
post #24

Monomorphization. For every generic function f, rustc will generate as many instances as there are type instances (shape instances? Does the Compiler distinguish between different kinds of references that all get compiled to pointers?). This feature has a cost. Compare to OCaml's uniform object representation that enables comparatively blazing compilation performance but pays a prize in performance and weird FFI rest…

D does the same thing with its template system and the compilation is still extremely fast.

Re: What part of Rust compilation is the bottleneck?

#29
post #9

Earlier quoted context omitted.

That is definitely true, but from the article it's the backend that takes time, not the frontend where the language itself resides. If you compile go from llvm, it maybe as long as rust.

It’s not just Rust. Practically every compiler based on LLVM is slow. Swift, Zig, Clang. The Go compiler being written from scratch based on the Plan9 C compiler is a huge advantage.

I will chime in to day that rust is also building a alternative to the LLVM backend in the form of cranelift : https://github.com/rust-lang/rustc_codegen_cranelift

Re: What part of Rust compilation is the bottleneck?

#30
post #27

One reason for me moving from Rust to Go was compilation speed. Go is a simpler language, so apples to oranges, but Go compiles so fast, which to me makes development very different.

OCaml compiles just as fast without having to compromise on the type system.

But then you have to compromise on speed of generated code, poor support of windows, number of libraries and overall ecosystem, no ability to generate standalone executables and probably more but I tried OCaml only briefly so can't speak to all of its shortcomings.
Post reply on HN