-
-
Notifications
You must be signed in to change notification settings - Fork 572
fix(allocator/vec2): guard against cap
rather than allocation size exceeding u32::MAX
#11064
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
base: main
Are you sure you want to change the base?
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
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.
Pull Request Overview
This pull request fixes the capacity guard logic in the vector allocator to check the capacity rather than the allocation size against u32::MAX. It replaces the old alloc_guard with the new cap_guard function, updates related calls in growth functions, and revises the associated comments.
- Replace alloc_guard with cap_guard in critical allocation and growth functions.
- Update inline documentation to accurately describe the guard behavior.
- Adjust error handling to use unwrap_err_unchecked in from_raw_parts_in.
63465bb
to
c1e4d69
Compare
CodSpeed Instrumentation Performance ReportMerging #11064 will not alter performanceComparing Summary
|
5065d07
to
11f8c00
Compare
u32::MAX
cap
rather than allocation size exceeding u32::MAX
11f8c00
to
97ba73b
Compare
Kinda relate to this PR because too many checks in Rust uses /cc @overlookmotel Maybe we can take this way to reduce some checks, what do you think? |
We have 3 checks:
We should ideally try to remove at least 1 of these checks, and possibly remove 2. We should be able to combine the last 2 checks, and create impl<'a, T> RawVec<'a, T> {
const MAX_CAP: usize = {
let max_cap_elements = u32::MAX as usize;
let max_cap_due_to_size = (isize::MAX as usize) / size_of::<T>();
min(max_cap_elements, max_cap_due_to_size)
};
}
const fn min(a: usize, b: usize) -> usize {
if a < b { a } else { b }
} Check if requested capacity is greater than We've now satisfied the conditions of (I think this covers both 32-bit and 64-bit systems) As to how to remove the oxc/crates/oxc_allocator/src/vec2/raw_vec.rs Lines 622 to 627 in c29b1b8
This last one may or may not be a perf gain. We remove one branch but the arithmetic takes more operations. |
@overlookmotel Thank you for reviewing this. I intend to work on it when you finish your work on |
I'm pretty much done with follow-up PRs about Concerning this PR: I'd be happy to leave it to you, if that's OK. |
Ah I see you've already reviewed most of that stack. I'll merge them now. Please review the last one #11081 when you get a chance. |
len
andcap
fields fromusize
tou32
#10884 (comment)Introduce a
cap_guard
to guard againstcap
exceedingu32::MAX
and revertalloc_guard
to before.