-
-
Notifications
You must be signed in to change notification settings - Fork 780
feat(allocator/vec2): change len and cap fields from usize to u32
#10884
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
feat(allocator/vec2): change len and cap fields from usize to u32
#10884
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. |
2cdf9ec to
faf29b6
Compare
882a193 to
b762280
Compare
CodSpeed Instrumentation Performance ReportMerging #10884 will not alter performanceComparing Summary
|
|
Can you report memory change https://github.com/oxc-project/bench-javascript-parser-written-in-rust/blob/main/memory.sh |
Not too much, 1.5% in cal.com.tsx and 3% in typescript.js. Before: ./files/cal.com.tsx
oxc 11.8 mb
swc 15.0 mb
biome 0.9 MB
./files/typescript.js
oxc 59.1 mb
swc 84.0 mb
biome 0.9 MBAfter: ./files/cal.com.tsx
oxc 11.6 mb
swc 15.0 mb
biome 0.9 mb
./files/typescript.js
oxc 57.3 mb
swc 84.0 mb
biome 0.9 MB |
|
So 2% memory reduction in In terms of speed, I think it's hard to judge the implications at present.
I've made a suggestion on #10883 for a faster way to get a more optimal implementation without tons of code changes. Maybe we should consider trying that and then assess perf again? |
b762280 to
b0b67b2
Compare
faf29b6 to
4192132
Compare
06f6eed to
5d77cbb
Compare
Thank you for reviewing this! I've taken your suggestion to re-implement this. Unfortunately, the current implementation has a 2% ~ 3% performance regression in the transformer. Probably caused by a subtle change somewhere, I will investigate a little bit on this. Anyway, your way is good! It is simpler than I thought. |
e26ab46 to
b24ad62
Compare
|
I may have found a little clue about the performance regression. When only changing |
|
A couple of thoughts:
e.g. in if self.buf.len == usize_to_u32(self.buf.cap()) {The
Again, this may make no difference, but I think worth a giving a go. By the way, don't worry about the raw transfer test fails. It's just because the layout of |
5e1cb8a to
2b94bc7
Compare
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.
Merge merge merge merge!
I removed the benchmarks image from PR description, because it's outdated.
Merge activity
|
91cad19 to
7d54577
Compare
7c5d8af to
3621d93
Compare
…u32` (#10884) Related: * #6488 * #9706 Finished first step(32 -> 24) of #9706. Change `len` and `cap` fields from `usize` to `u32`, so that the `Vec` size can reduced size to `24`. Also, to avoid some unnecessary unit conversion. I changed many `RawVec` methods to take `u32` rather than `usize`. The performance looks great now! And we reduced 1%-3% memory usage in the parser.
3621d93 to
c60382d
Compare
|
@Dunqing Just to make sure you saw my comments above. I had to mark them as "resolved" just to be able to merge the PR. But they're not resolved... |
Thanks! I saw! I am going to solve the #10884 (comment) problem. |
Follow-on after #10884. Clarify comment as to why `as u32` is valid here.
…ents` (#11072) Follow-on after #10884. The original safety conditions aren't required any more, because of the change made to `Vec::reserve` in #10884 - `reserve` will panic if `other.len` or `self.len + other.len` exceeds `u32::MAX`. So nothing can go wrong if these conditions aren't satisfied. Which is lucky, because `append` doesn't do anything to make sure `self.len + other.len <= u32::MAX`! `append_elements` originally had no safety docs at all (naughty bumpalo!). So add some.
…s_in` + clarify safety docs (#11073) Follow-on after #10884. We don't need `alloc_guard` here. `RawVec::from_raw_parts_in` is an unsafe method, and caller guarantees that `len` and `capacity` are in legal range. We don't need to check the caller fulfilled that guarantee - that responsibility is on them. Also clarify the safety docs for this method.
…le_truncation)]` (#11074) Follow-on after #10884. Pure refactor. Move the `#[expect(clippy::cast_possible_truncation)]` attributes so they only apply to a single statement, rather than the whole function. That way we can see clearly where there's a dangerous conversion happening. Annoyingly Rust doesn't allow putting attributes on expressions, so this requires statements that can then be attributed-up. But in my view, it's worth it.
…tters (#11081) Follow-on after #10884. Pure refactor. To make it explicit when we're converting `u32` to/from `usize`: * Make `RawVec`'s `len` field private. * Make all access to `len` and `cap` fields go via getter/setter methods. * Name those methods `*_u32` and `*_usize` so it's clear when a conversion is happening. I also renamed `cap_*` methods to `capacity_*` for consistency with `Vec::capacity`. I haven't used these methods in `RawVec` because there's some subtlety around when you want the "raw" `cap` value, and when you want the value `capacity` method returns, which is different when `T` is a ZST. Hopefully we can remove support for ZSTs, and remove this ambiguity.

Related:
Vecto 24 #9706Finished first step(32 -> 24) of #9706.
Change
lenandcapfields fromusizetou32, so that theVecsize can reduced size to24. Also, to avoid some unnecessary unit conversion. I changed manyRawVecmethods to takeu32rather thanusize.The performance looks great now! And we reduced 1%-3% memory usage in the parser.