Reserve before write_fmt
for owned buffers by thaliaarchi · Pull Request #137762 · rust-lang/rust (original) (raw)
I checked cachegrind on the biggest doc regression of the perf run and found this:
> 353,086,439 <alloc:🧵:String as core::fmt::Write>::write_fmt:???
> -190,119,423 <alloc::raw_vec::RawVecInner<_>>::reserve::do_reserve_and_handle::<alloc::alloc::Global>:???
> 152,807,999 alloc::raw_vec::finish_grow:???
> 148,657,316 alloc::raw_vec::RawVecInner<A>::reserve::do_reserve_and_handle:???
> -101,526,039 alloc::raw_vec::finish_grow::<alloc::alloc::Global>:???
> -71,185,707 __memcpy_avx_unaligned_erms:???
> -61,348,606 __rustc::__rust_realloc:???
> 51,174,119 alloc::fmt::format::format_inner:???
> 24,400,284 <alloc:🧵:String as core::fmt::Write>::write_str:???
> -15,782,380 alloc:🧵:String::push:???
> 12,910,951 <alloc:🧵:String as core::fmt::Write>::write_char:???
> -4,769,649 __rustc::__rust_alloc:???
as usual inlining noise makes it harder to understand, but it does look like it's spending more instructions (which of course don't necessarily have to mean that it's actually slower, but it's a sign) around the code you changed, generally (formatting and appending things to vecs). rustdoc uses a lot of formatting into strings