-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Reduce default 'large array' threshold #13485
Conversation
I would like to suggest a default of 64KiB, 16KiB, or 4KiB instead. This is because those are precisely the allocation granularity for certain memory mappings and anyone who is copying data structures of those size around is prooobably doing it on purpose? Doubly so if they are actually aligned to that value. Also there are architectures where values in the range 2KiB to 64KiB are in fact possible sizes for single registers. |
What do you think? I agree that the 1kib number may be a little low, but the specific context here makes me think this should be kept as in this PR. |
Hmm. Other architectural trivia that you may wish to consider: 32KiB, 16KiB or 8KiB as a limit also might make sense because many CPUs, even 32-bit ones, have around 32KiB as their L1 data cache size. That's true for x86 CPUs since the Pentium M, and the ever-popular-to-use-as-reference Raspberry Pi has it at 16KiB for the first one up to 64KiB on recent ones. So anything larger than 16KiB can't be copied without hitting the L2 cache on a lot of CPUs. Basically: copies of a few KiB are still relatively cheap on most application processors, and even very low-power application processors like the Pi are still massively beefier than an embedded MCU in this regard. Usually if something is only applicable to a few projects it's a restriction lint, and aiui the value for this lint can be altered. So even if pedantic, it still seems sensible to try to put it at a default value where most people would feel concerned. In particular, the stdlib uses around 8KiB as a value for all its on-stack arrays, too, for most targets. It might even be worth considering a target-specific default? |
fwiw I think it's obvious we should drop it below 512KB that's just kinda "what" |
I'm good with the a 16kib default, that's a number that makes my brain happy. I'll swap that over in a bit. @rustbot author |
78d34c4
to
66babb5
Compare
Just bumped it up to 16kib @workingjubilee @rustbot ready |
66babb5
to
995eb95
Compare
The changes look good to me. 16kb sounds reasonable, if people need a lower value, they can still change the default. It would be cool to have configuration templates, for example for embedded development. But that's an idea and a totally different topic :D Thank you for the changes! And also thank you @workingjubilee for the input. Roses are red, |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
1 similar comment
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
👀 Test was successful, but fast-forwarding failed: 422 Changes must be made through a pull request. |
@@ -5182,7 +5182,7 @@ impl ShouldImplTraitCase { | |||
} | |||
|
|||
#[rustfmt::skip] | |||
const TRAIT_METHODS: [ShouldImplTraitCase; 30] = [ | |||
static TRAIT_METHODS: [ShouldImplTraitCase; 30] = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change breaks the Clippy sync when testing the parallel compiler: rust-lang/rust#131892
IIUC: With this being a static
, it must implement Sync
, but since Span
doesn't implement Sync
this also doesn't implement sync.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, for now we can revert back to const
and add an allow if it fires. Longer term we should look at why Span isn't Sync.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in rust-lang/rust@cf918d5
As-is this threshold is
512kb
, but as #9449 points out this is way too high for most people to consider sensible (why would you want to copy256kb
of data around on the stack or duplicate it viaconst
) and didn't get any discussion when originally added. This PR reduces it the threshold to1kb
, which is higher than the issue says ("a few cpu words") but helps out for actual codebases.While reducing this, I found that
large_stack_arrays
was triggering for statically promoted arrays in constants/statics, so I also fixed that up as seen in the difference to array_size_threshold.stderr.Closes #9449.
changelog: [
large_stack_arrays
]: No longer triggers instatic
/const
contextchangelog: [
large_const_arrays
]: Changed the default of [array-size-threshold
] from512kb
to16kb