perf(transformer/refresh): use take/take_in instead of drain#10656
Merged
graphite-app[bot] merged 1 commit intomainfrom Apr 30, 2025
Merged
Conversation
Member
Author
CodSpeed Instrumentation Performance ReportMerging #10656 will not alter performanceComparing Summary
|
0479363 to
68620ef
Compare
aecfae5 to
3648471
Compare
This was referenced Apr 28, 2025
Merged
3648471 to
c01878f
Compare
68620ef to
b44d2a9
Compare
b44d2a9 to
91df9d4
Compare
c01878f to
58652a1
Compare
58652a1 to
25f8411
Compare
overlookmotel
approved these changes
Apr 29, 2025
Member
There was a problem hiding this comment.
Good spot. Though I'm not actually sure how much take_in gains over drain(..) here. The code for drain contains more instructions, but in the case of drain(..) compiler may be able to optimize most of them out. Maybe. That's just guesswork.
I suspect the perf gain in this PR is more due to:
- let mut new_statements = ctx.ast.vec_with_capacity(program.body.len());
+ let mut new_statements = ctx.ast.vec_with_capacity(program.body.len() * 2);...so new_statements will never need to grow and reallocate during the loop.
I can see another couple of things. I'll do a follow-up PR.
Member
Merge activity
|
graphite-app bot
pushed a commit
that referenced
this pull request
Apr 29, 2025
) Calling `take` is cheaper than calling `drain`. These cases don't need to reuse the `Vec` after it drained, so we can replace them with `take`, which gives a tiny performance improvement. <img width="633" alt="image" src="https://github.com/user-attachments/assets/a2a65957-09a0-47a5-9b9f-eaec576220c1" />
25f8411 to
04db587
Compare
) Calling `take` is cheaper than calling `drain`. These cases don't need to reuse the `Vec` after it drained, so we can replace them with `take`, which gives a tiny performance improvement. <img width="633" alt="image" src="https://github.com/user-attachments/assets/a2a65957-09a0-47a5-9b9f-eaec576220c1" />
04db587 to
7d8efd8
Compare
graphite-app bot
pushed a commit
that referenced
this pull request
Apr 30, 2025
Follow-on after #10656. Remove the temporary `Vec` `new_statements`. Append new statements directly to `program.body` instead. We get around the fact that the `VariableDeclaration` has to be inserted first by initially pushing a `VariableDeclaration` with no declarators, and then setting its declarators at the end.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Calling
takeis cheaper than callingdrain. These cases don't need to reuse theVecafter it drained, so we can replace them withtake, which gives a tiny performance improvement.