Conversation
…/after_current_statement methods
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. |
insert_*_before/after_current_statement methods
CodSpeed Performance ReportMerging #9061 will not alter performanceComparing Summary
|
overlookmotel
left a comment
There was a problem hiding this comment.
I'm afraid I'm not convinced this is a good idea overall.
On the positive side, as you say, it removes common repeated code - great.
But on the negative side, it's doing extra work on every statement (very hot path) to update current_statement_address. For the majority of statements, no transform ever needs to know their address, so that work is wasted.
This PR is currently showing -1% on some of the transformer benchmarks. I believe that to make it correct, it'll require a stack (see comment below) which is more expensive, so the perf impact will increase further.
I wonder if there's another way to get the nice API without the perf impact?
How about insert_before_current_statement etc taking &TraverseCtx and they search up the ancestry chain to find the current statement? Then the work would only be done when it needs to be done, rather than eagerly? Do you think something like that could work?
| fn exit_statement(&mut self, stmt: &mut Statement<'a>, ctx: &mut TraverseCtx<'a>) { | ||
| self.statement_injector.exit_statement(stmt, ctx); | ||
| } |
There was a problem hiding this comment.
I don't think this can be correct. When exiting a statement, don't you need to restore the address of the parent statement? e.g.:
const x = () => {
let y;
};After exiting the statement let y, the current statement is const x = ... again.
I guess would need a stack to achieve this.
There was a problem hiding this comment.
Ah, This big problem I've overlooked. Thanks for pointing it out
This is feasible in most scenarios. I added these APIs to solve a problem when we want to do some transformation in |
|
Converted to draft as it is not ideal, and I changed another way to solve #9062, please review that PR, which blocks Rolldown from advancing the legacy decorator feature. |

These methods allow inserting statements before or after the current statement without needing the statement address. And can reduce the address looking up logic like
oxc/crates/oxc_transformer/src/es2022/class_properties/class.rs
Lines 434 to 440 in c35f52b
This is also an alternative to oxc-project/backlog#140.