-
Notifications
You must be signed in to change notification settings - Fork 12.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
Take more advantage of the isize::MAX
limit in Layout
#129845
Conversation
r? @Noratrieb rustbot has assigned @Noratrieb. Use |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Take more advantage of the `isize::MAX` limit in `Layout` Things like `padding_needed_for` are current implemented being super careful to handle things like `Layout::size` potentially being `usize::MAX`. But now that rust-lang#95295 has happened, that's no longer a concern. It's possible to add two `Layout::size`s together without risking overflow now. So this PR adds a wrapper type to allow doing that kind of thing in safe code while still telling LLVM it can't overflow.
This comment has been minimized.
This comment has been minimized.
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (3e6e03e): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)Results (primary 0.3%, secondary 0.1%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (primary 0.8%, secondary 0.6%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeResults (primary 0.6%, secondary 1.6%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Bootstrap: 789.43s -> 800.421s (1.39%) |
3fcde40
to
972ff01
Compare
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Take more advantage of the `isize::MAX` limit in `Layout` Things like `padding_needed_for` are current implemented being super careful to handle things like `Layout::size` potentially being `usize::MAX`. But now that rust-lang#95295 has happened, that's no longer a concern. It's possible to add two `Layout::size`s together without risking overflow now. So this PR adds a wrapper type to allow doing that kind of thing in safe code while still telling LLVM it can't overflow.
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (9c711ef): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)Results (primary -0.2%, secondary -0.6%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (primary 0.6%, secondary 0.4%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeResults (primary 0.6%, secondary 1.6%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Bootstrap: 787.22s -> 796.262s (1.15%) |
972ff01
to
e9ac905
Compare
This comment has been minimized.
This comment has been minimized.
e9ac905
to
7ccc088
Compare
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (c8e94c4): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)Results (primary -0.1%, secondary -0.9%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (primary -0.5%, secondary -0.4%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeResults (primary -0.0%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Bootstrap: 751.284s -> 755.684s (0.59%) |
Ah, there we go. #129845 (comment) looks great. @rustbot ready |
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.
two comments, which you may optionally address
library/core/src/alloc/layout.rs
Outdated
// The safe constructor is called here to enforce the isize size limit. | ||
Layout::from_size_alignment(new_size, self.align) | ||
pub const fn extend_packed(&self, next: Self) -> Result<Self, LayoutError> { | ||
if let Some(new_size) = self.size.checked_add(next.size) { |
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 can't overflow, right?
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.
True!
library/core/src/alloc/layout.rs
Outdated
/// because the original size is at most `isize::MAX`. | ||
#[inline] | ||
const fn size_rounded_up_to_custom_align(&self, align: Alignment) -> usize { | ||
let len = self.size; |
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 variable with a slighty confusing name is used once, can we just remove it and call it "size" instead of "len" everywhere?
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.
Good point. I'd left it because it was in the old code, but apparently I then refactored enough that the diff doesn't notice that, so might as well just remove it as you say.
7ccc088
to
b824dc4
Compare
@bors r=Noratrieb |
b824dc4
to
29262a1
Compare
Things like `padding_needed_for` are current implemented being super careful to handle things like `Layout::size` potentially being `usize::MAX`. But now that 95295 has happened, that's no longer a concern. It's possible to add two `Layout::size`s together without risking overflow now. So take advantage of that to remove a bunch of checked math that's not actually needed. For example, the round-up-and-add-next-size in `extend` doesn't need any overflow checks at all, just the final check for compatibility with the alignment. (And while I was doing that I made it all unstably const, because there's nothing in `Layout` that's fundamentally runtime-only.)
29262a1
to
18ca8bf
Compare
Diff fixing the PR comments: https://github.com/rust-lang/rust/compare/7ccc088c808f0ba169824dd9f6cdd83000a8b8ac..18ca8bf8ee77deb13967620b1f4829f22c16dae1 (multiple pushes because apparently I'm bad at updating comments) @bors r=Noratrieb |
☀️ Test successful - checks-actions |
Finished benchmarking commit (f68c28b): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)Results (primary -0.9%, secondary -2.1%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (secondary 2.6%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeResults (primary -0.0%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Bootstrap: 767.306s -> 765.816s (-0.19%) |
Things like
padding_needed_for
are current implemented being super careful to handle things likeLayout::size
potentially beingusize::MAX
.But now that #95295 has happened, that's no longer a concern. It's possible to add two
Layout::size
s together without risking overflow now.So take advantage of that to remove a bunch of checked math that's not actually needed. For example, the round-up-and-add-next-size in
extend
doesn't need any overflow checks at all, just the final check for compatibility with the alignment.(And while I was doing that I made it all unstably const, because there's nothing in
Layout
that's fundamentally runtime-only.)