-
-
Notifications
You must be signed in to change notification settings - Fork 756
fix(allocator)!: make Vec non-drop
#6623
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
Conversation
Your org has enabled the Graphite merge queue for merging into mainAdd the label “0-merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix. You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link. |
This stack of pull requests is managed by Graphite. Learn more about stacking. Join @overlookmotel and the rest of your teammates on |
Vec non-dropVec non-drop
CodSpeed Performance ReportMerging #6623 will improve performances by 8.41%Comparing Summary
Benchmarks breakdown
|
90ddf67 to
749695e
Compare
|
What does this all mean? |
749695e to
8ddc979
Compare
|
@Boshen I think this change is worthwhile. It's improving perf pretty much across the board, and #6626 demonstrates that it does not introduce any memory leaks within Oxc. However, we should probably first check that Rolldown is not erroneously using Alternatively, we could hold off merging this until we have static checks (like #6626, but more robust) that make it impossible to put |
7156eaa to
2673397
Compare
8ddc979 to
3e8b3ed
Compare
3e8b3ed to
45bdb68
Compare
|
I'll test Rolldown after the next oxc release. |
|
OK great. I think this can be merged then. I'll leave it to you to merge Boshen in case you want to check the code first. |
Merge activity
|
`oxc_allocator::Vec` is intended for storing AST types in the arena. `Vec` is intended to be non-drop, because all AST types are non-drop. If they were not, it would be a memory leak, because those types will not have `drop` called on them when the allocator is dropped. However, `oxc_allocator::Vec` is currently a wrapper around `allocator_api2::vec::Vec`, which *is* drop. That unintentionally makes `oxc_allocator::Vec` drop too. This PR fixes this by wrapping the inner `allocator_api2::vec::Vec` in `ManuallyDrop`. This makes `oxc_allocator::Vec` non-drop. The wider consequence of this change is that the compiler is now able to see that loads of other types which contain `oxc_allocator::Vec` are also non-drop. Once it can prove that, it can remove a load of code which handles dropping these types in the event of a panic. This probably also then allows it to make many further optimizations on that simplified code. Strictly speaking, this PR is a breaking change. If `oxc_allocator::Vec` is abused to store drop types, then in some circumstances this change could produce a memory leak where there was none before. However, we've always been clear that only non-drop types should be stored in the arena, so such usage was always a bug. #6622 fixes the only place in Oxc where we mistakenly stored non-drop types in `Vec`. The change to `oxc_prettier` is because compiler can now deduce that `Doc` is non-drop, which causes clippy to raise a warning about using `then` instead of `then_some`. As follow-up, we should: 1. Wrap other `allocator_api2` types (e.g. `IntoIter`) in `ManuallyDrop` too, so compiler can prove they are non-drop too (or reimplement `Vec` ourselves - #6488). 2. Introduce static checks to prevent non-drop types being used in `Box` and `Vec`, to make memory leaks impossible, and detect them at compile time.
45bdb68 to
e1c2d30
Compare
Partially revert #6623, It still keeps the check for non-`drop` element of `Vec`

oxc_allocator::Vecis intended for storing AST types in the arena.Vecis intended to be non-drop, because all AST types are non-drop. If they were not, it would be a memory leak, because those types will not havedropcalled on them when the allocator is dropped.However,
oxc_allocator::Vecis currently a wrapper aroundallocator_api2::vec::Vec, which is drop. That unintentionally makesoxc_allocator::Vecdrop too.This PR fixes this by wrapping the inner
allocator_api2::vec::VecinManuallyDrop. This makesoxc_allocator::Vecnon-drop.The wider consequence of this change is that the compiler is now able to see that loads of other types which contain
oxc_allocator::Vecare also non-drop. Once it can prove that, it can remove a load of code which handles dropping these types in the event of a panic. This probably also then allows it to make many further optimizations on that simplified code.Strictly speaking, this PR is a breaking change. If
oxc_allocator::Vecis abused to store drop types, then in some circumstances this change could produce a memory leak where there was none before. However, we've always been clear that only non-drop types should be stored in the arena, so such usage was always a bug.#6622 fixes the only place in Oxc where we mistakenly stored non-drop types in
Vec.The change to
oxc_prettieris because compiler can now deduce thatDocis non-drop, which causes clippy to raise a warning about usingtheninstead ofthen_some.As follow-up, we should:
allocator_api2types (e.g.IntoIter) inManuallyDroptoo, so compiler can prove they are non-drop too (or reimplementVecourselves - test: reduce size of vec #6488).BoxandVec, to make memory leaks impossible, and detect them at compile time.