-
-
Notifications
You must be signed in to change notification settings - Fork 729
perf(minifier/minimize_statements): reduce allocations of Vec
#10435
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
perf(minifier/minimize_statements): reduce allocations of Vec
#10435
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. |
CodSpeed Instrumentation Performance ReportMerging #10435 will not alter performanceComparing Summary
|
609c523 to
da697ef
Compare
ccdd6e9 to
07fcd0b
Compare
07fcd0b to
d9f2655
Compare
da697ef to
c7e72f5
Compare
VecVec
d9f2655 to
b645ac3
Compare
c7e72f5 to
161afb6
Compare
Merge activity
|
|
Actually I think this might be even better: Before: let drained_stmts = stmts.drain(i + 1..);
let mut body = if let Some(alternate) = if_stmt.alternate.take() {
ctx.ast.vec_from_iter(iter::once(alternate).chain(drained_stmts))
} else {
ctx.ast.vec_from_iter(drained_stmts)
};After: let mut body = if let Some(alternate) = if_stmt.alternate.take() {
let drained_stmts = stmts.drain(i + 1..);
ctx.ast.vec_from_iter(iter::once(alternate).chain(drained_stmts))
} else {
stmts.split_off(i + 1)
};
Similar to my comment on preceding PR #10434 (comment), later on we can make our Then this simpler version would be equally efficient (or possibly more, as if let mut body = stmts.split_off(i + 1);
if let Some(alternate) = if_stmt.alternate.take() {
body.insert(0, alternate);
} |
161afb6 to
59e35c3
Compare
b645ac3 to
1f77cac
Compare
Use `ctx.ast.vec_from_iter` to allocate a `Vec` for the result of `drain` and use `take_in` to take a `Vec` rather than use `vec_from_iter` + `drain` to avoid intermediate allocation. <img width="742" alt="image" src="https://github.com/user-attachments/assets/10011073-6706-435a-8d79-0b805e14f20c" />
1f77cac to
595c5df
Compare
59e35c3 to
2eb60b3
Compare

Use
ctx.ast.vec_from_iterto allocate aVecfor the result ofdrainand usetake_into take aVecrather than usevec_from_iter+drainto avoid intermediate allocation.