Help reading cargo llvm-lines

I have a large workspace with a 'root crate'. The 'root crate' is < 1000 lines and takes 3+s to build. This is not a big deal, but I'm curious where the time is going to.

I run cargo llvm-lines, and I get back:

  Lines         Copies       Function name
  -----         ------       -------------
  56667 (100%)  1997 (100%)  (TOTAL)
  12999 (22.9%)   61 (3.1%)  <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop
   1791 (3.2%)    26 (1.3%)  alloc::rc::Rc<T>::new
   1749 (3.1%)    34 (1.7%)  alloc::rc::RcInnerPtr::inc_strong
   1221 (2.2%)    12 (0.6%)  <alloc::boxed::Box<T,A> as core::ops::drop::Drop>::drop
   1038 (1.8%)    84 (4.2%)  alloc::rc::RcInnerPtr::strong
    955 (1.7%)    54 (2.7%)  alloc::boxed::Box<T>::new
    780 (1.4%)    34 (1.7%)  <alloc::rc::Rc<T> as core::clone::Clone>::clone
    776 (1.4%)    13 (0.7%)  dominator::utils::EventListener::new
    762 (1.3%)    61 (3.1%)  alloc::rc::RcInnerPtr::weak
    630 (1.1%)     6 (0.3%)  alloc::raw_vec::RawVec<T,A>::current_memory
    629 (1.1%)     6 (0.3%)  <core::slice::iter::Iter<T> as core::iter::traits::iterator::Iterator>::next
    585 (1.0%)     5 (0.3%)  <futures_util::stream::stream::for_each::ForEach<St,Fut,F> as core::future::future::Future>::poll

Am I reading this right? Something like 30% of the time llvm spends on compiling the root crate is going to ... instantiating Rc<T>'s ?

Not necessarily; llvm-lines numbers are not about time, they are about lines. That said, there is some correlation between amount-of-code and time-to-compile-code.

Looks like you instantiate dozens of types of Rc (and Box).


Are you sure the 3 seconds are LLVM and not, say, the linker? On nightly you can run with RUSTFLAGS="-Z time-passes".

RUSTCFLAGS="-Z time-passes" cargo +nightly build --release --timings

sorry, where does the time-passes data get written to ?

(I still can't see output of Z time-passes)

I just tried using mold instead, and it appears to have taken it from 3s down to 1s.

Looks like your intuition was right: linker issue.

It's RUSTFLAGS not RUSTCFLAGS. They're printed to the terminal by default (there's some JSON format option too, not sure if that writes a file or also outputs to terminal; see rustc -Z help).