-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code bloat from monomorphization of methods applied to arrays #77767
Comments
We could insert a shim For other traits, I'd worry about hurting bounds-checking and vectorization if we add artificial barriers. |
Given that these things are already implemented by calling the slice versions, I don't know that there's actually anything array-specific here. This is just the inliner doing what it's told to do. The same thing will plausibly happen with Given that Even for debug it's not obvious to me that Note that neither the array nor slice implementations of rust/library/core/src/array/mod.rs Lines 184 to 189 in 9a8ca69
rust/library/core/src/fmt/mod.rs Lines 2166 to 2171 in 9a8ca69
so this is all LLVM's inlining heuristic deciding that this is a good bet with no extra encouragement. Were you seeing a regression here? I suppose that this could have changed last summer when we started using const generics for them, or if one of the LLVM upgrades changed the inlining heuristics... |
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: