News for hackers. Stuff that matters.
Re:Why is my Rust build so slow? by aliceryhl on Friday December 31, 2021 @05:15AM (#29746542)
Tokio maintainer here. I've actually been spending a bunch of time recently looking in to how we can reduce Tokio's compile-times. I haven't really been able to find any big wins yet, but one thing has been pretty clear from the benchmarks: The number of dependencies of Tokio is not the problem. They all compile pretty fast and can all compile in parallel. Tokio itself takes a lot longer than the dependencies.

(Except for tokio-macros which takes a long time because it depends on syn and quote. Consider disabling it if you don't need it.)

Re:Why is my Rust build so slow? by formerly_proven on Friday December 31, 2021 @07:10AM (#29747303)
So I've read "syn" and "slow rust compiles" in pretty much every discussion of "slow rust compiles" and finally googled it and... syn is a Rust parser? For use in macros? Because procedural macros operate on tokens and not an AST? Hm. I'm sure there are reasons for how it ended up like this, but it does smell kinda funny.
Re:Why is my Rust build so slow? by Cu3PO42 on Friday December 31, 2021 @09:16AM (#29748228)
If I recall the reason is "rustc's representation of the AST is an implementation detail and unstable, thus macro code may not rely on it (and it will not be exposed)". Hence "syn" came along and provided a stable API and format. "quote" is the inverse function, turning an AST back into tokens.
Re:Why is my Rust build so slow? by jhgg on Friday December 31, 2021 @07:53AM (#29747570)
It allows for things like https://docs.rs/typed-html/latest/typed_html/ to exist.
Re:Why is my Rust build so slow? by dom96 on Friday December 31, 2021 @08:32AM (#29747842)
This is quite interesting. Is `syn` just an interface to the Rust compiler's Rust parser or is it a completely separate implementation of the parser that works at compile-time?

Hopefully it's not the latter but then I wonder where the slowness comes from.

Re:Why is my Rust build so slow? by varajelle on Friday December 31, 2021 @08:53AM (#29748039)
it's a completely separate implementation of the parser

I wish that the proc_macro API from the compiler would do that instead.

Re:Why is my Rust build so slow? by estebank on Friday December 31, 2021 @12:48PM (#29750463)
syn also let's you define your own parsers for non-Rust syntax, way beyond what rustc could provide.
Re:Why is my Rust build so slow? by mamcx on Friday December 31, 2021 @10:59AM (#29749213)
Macros.

This is a major pain. I wish it get more attention (and hopefully: How about a SINGLE way to do macros? Like zig?).

Serde is another killer on compiling speed.

Re:Why is my Rust build so slow? by aliceryhl on Sunday January 02, 2022 @05:05AM (#29767383)
Well, one of the advantages of having two ways to do macros is that macro_rules! macros are much much faster than procedural macros.
Re:Why is my Rust build so slow? by mamcx on Monday January 03, 2022 @01:20PM (#29784166)
Yeah, but then why not make it the only one? One reason is that proc-macros can "see" the syntax outside the point of declaration(or enclosed). This means you must do macro_rules! {struct.... } instead of declare the struct first then forward it.
Re:Why is my Rust build so slow? by snorkel on Friday December 31, 2021 @07:22AM (#29747395)
First of all, Tokio is my favorite async framework, so thank you and the Tokio team! And second, I appreciate that cargo/rustc compiler errors are clear, helpful, and guide me toward cleaner and thread-safe coding where most other languages happily let me create unsafe hidden race bugs all day long with no warning … oh but they compile so much faster! (I don’t care) The slower compile time really doesn’t bother me when I’m getting a more stable end result… but I’m glad the maintainers are working on improving compile time anyway.

To me the extra compile time makes sense when rust is showing me many unsafe coding issues that languages seem to ignore even with their strict warnings enabled.

… and I don’t get all of the complaining about rust. I’ve written code in a lot of languages and rust has its quirks too, as they all do, but I really like it!