←back to thread

302 points Bogdanp | 1 comments | | HN request time: 0.221s | 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. lor_louis ◴[] No.44400956[source]
I write a lot of C and Rust, and my personal experience is that for smaller C programs, Rust tends to have a slightly higher line count, but it's mostly due to forcing the user to handle every error possible.

A truly robust C program will generally be much larger than the equivalent Rust program.