←back to thread

302 points Bogdanp | 1 comments | | HN request time: 0.205s | source
Show context
dminik ◴[] No.44396855[source]
One aspect that I find interesting is that Rust projects often seem deceivingly small.

First, dependencies don't translate easily to the perceived size. In C++ dependencies on large projects are often vendored (or even not used at all). And so it is easy to look at your ~400000 line codebase and go "it's slow, but there's a lot of code here after all".

Second (and a much worse problem) are macros. They actually hit the same issue. A macro that expands to 10s or 100s of lines can very quickly take your 10000 line project and turn it into a million line behemoth.

Third are generics. They also suffer the same problem. Every generic instantiation is eating your CPU.

But I do want to offer a bit of an excuse for rust. Because these are great features. They turn what would have taken 100000 lines of C or 25000 lines of C++ to a few 1000s lines of Rust.

However, there is definitely an overuse here making the ecosystem seem slow. For instance, at work we use async-graphql. The library itself is great, but it's an absolute proc-macro hog. There's issues in the repository open for years about the performance. You can literally feel the compiler getting slower for each type you add.

replies(3): >>44397321 #>>44399662 #>>44400438 #
1vuio0pswjnm7 ◴[] No.44400438[source]
"They turn what would have taken 100000 lines of C or 25000 lines of C++ to a few 1000s lines of Rust."

How do they do with smaller programs that would have taken far less than 100,000 lines of C.

For whatever reasons, many authors choose to rewrite small C utilties, or create similar ones, using Rust.^1 Perhaps there are countless examples of 100,000 line C programs rewritten in Rust but the ones I see continually submitted to HN, Github and elsewhere are much smaller.

How does Rust compilation time compare with C for smaller programs.

NB. I am not asking about program size. I am asking about compilation speed.

(Also curious about resource usage, e.g. storage, memory. For example, last time I measured, Rust compiler toolchain is about 2x as large as the GCC toolchain I am using.)

1. Some of these programs due to their size seem unlikely to have undetected memory-safety issues in any language. Their size makes them relatively easy to audit. Unlike a 100,000 line C program.

replies(2): >>44400956 #>>44401418 #
1. dminik ◴[] No.44401418[source]
Well, unfortunately I don't have an exact answer for you, but I do have the next best thing: speculation.

I had a quick look and found this article that compares a partial port of a C++ codebase (at around 17kloc). https://quick-lint-js.com/blog/cpp-vs-rust-build-times/

The resulting rust code apparently ended up slightly larger. This isn't entirely unsurprising to me despite the 25:1 figure from above. Certain things are much more macro-able than others (like de/serialization). Note that C++ is actually well positioned to level the field here with C++26 reflection.

Despite the slightly larger size, the compile times seem roughly equal. With rust scaling worse as the size increases. As a side-note, I did find this part relevant to some of my thoughts from above:

> For example, proc macros would let me replace three different code generators

Now, I know that C isn't C++. But, I think that when restricting yourself to a mostly C-like subset (no proc-macros, mostly no generics outside Option/Result) the result would likely mirror the one above. Depending on the domain and work needed, either language could be much shorter or longer. For example, anything involving text would likely be much shorter in rust as the stdlib has UTF-8 handling built-in. On the other hand, writing custom data structures would likely favor C.

I am interested to see if TRACTOR could help here. Being able to port C code to Rust and then observe the compile times would be pretty interesting. https://www.darpa.mil/research/programs/translating-all-c-to...