News for hackers. Stuff that matters.
Re:"Why is the Rust compiler so slow?" by vbezhenar on Thursday June 26, 2025 @05:47PM (#44391818)
Is it possible to generate less junk? Sounds like compiler developers took a shortcuts, which could be improved over time.
Re:"Why is the Rust compiler so slow?" by zozbot234 on Thursday June 26, 2025 @06:29PM (#44392115)
You can address the junk problem manually by having generic functions delegate as much of their work as possible to non-generic or "less" generic functions (Where a "less" generic function is one that depends only on a known subset of type traits, such as size or alignment. Then delegating can help the compiler generate fewer redundant copies of your code, even if it can't avoid code monomorphization altogether.)
Re:"Why is the Rust compiler so slow?" by andrepd on Friday June 27, 2025 @03:41AM (#44394609)
Isn't something like this blocked on the lack of specialisation?
Re:"Why is the Rust compiler so slow?" by dwattttt on Friday June 27, 2025 @07:20AM (#44395868)
I believe the specific advice they're referring to has been stable for a while. You take your generic function & split it into a thin generic wrapper, and a non-generic worker.

As an example, say your function takes anything that can be turned into a String. You'd write a generic wrapper that does the ToString step, then change the existing function to just take a String. That way when your function is called, only the thin outer function is monomorphised, and the bulk of the work is a single implementation.

It's not _that_ commonly known, as it only becomes a problem for a library that becomes popular.

Re:"Why is the Rust compiler so slow?" by estebank on Friday June 27, 2025 @10:55AM (#44397255)
To illustrate:

  fn foo<S: Into<String>>(s: S) {
      fn inner(s: String) { ... }
      inner(s.into())
  }
Re:"Why is the Rust compiler so slow?" by rcxdude on Thursday June 26, 2025 @06:13PM (#44392001)
Probably, but it's the kind of thing that needs a lot of fairly significant overhauls in the compiler architecture to really move the needle on, as far as I understand.
Re:"Why is the Rust compiler so slow?" by LtdJorge on Friday June 27, 2025 @04:16AM (#44394849)
Well, zero-cost abstractions are still abstractions. It’s not junk per-se, but things that will be optimized out if the IR has enough information to safely do so, so basically lots of extra metadata to actually prove to LLVM that these things are safe.