-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Open
Labels
A-arrayArea: `[T; N]`Area: `[T; N]`A-fmtArea: `core::fmt`Area: `core::fmt`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.I-heavyIssue: Problems and improvements with respect to binary size of generated code.Issue: Problems and improvements with respect to binary size of generated code.
Description
The following talks about Debug::fmt
, but is likely true of a lot more methods applied to arrays.
Take the following code:
fn main() {
let a = [1, 2, 3];
let b = [1, 2, 3, 4];
let c = [1, 2, 3, 4, 5];
let d = [1, 2, 3, 4, 5, 6];
println!("{:?}", a);
println!("{:?}", b);
println!("{:?}", c);
println!("{:?}", d);
}
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 in core::array::<impl core::fmt::Debug for [T; N]>::fmt
if that were possible.
Corallus-Caninus and Virgiel
Metadata
Metadata
Assignees
Labels
A-arrayArea: `[T; N]`Area: `[T; N]`A-fmtArea: `core::fmt`Area: `core::fmt`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.I-heavyIssue: Problems and improvements with respect to binary size of generated code.Issue: Problems and improvements with respect to binary size of generated code.