Code bloat from monomorphization of methods applied to arrays #77767
Labels
A-array
Area: `[T; N]`
A-fmt
Area: `core::fmt`
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
I-heavy
Issue: Problems and improvements with respect to binary size of generated code.
The following talks about
Debug::fmt
, but is likely true of a lot more methods applied to arrays.Take the following code:
Compiled with --release, you end up with 4 different functions for
core::array::<impl core::fmt::Debug for [T; N]>::fmt
(BTW, shouldn't they each have their N replaced by the actual number?). To add insult to injury, each of these have their loops unrolled, so the longer the array, the larger the function, up to 59 (!).Almost ironically, building with
-C opt-level=1
generates 4 functions that create a slice and a separate, common,fmt
function for it.This is one of these cases where you'd probably want a
#[inline(never)]
at the call site incore::array::<impl core::fmt::Debug for [T; N]>::fmt
if that were possible.The text was updated successfully, but these errors were encountered: