-
-
Notifications
You must be signed in to change notification settings - Fork 726
perf(transformer/tagged-template-transform): improve performance #15834
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
base: main
Are you sure you want to change the base?
perf(transformer/tagged-template-transform): improve performance #15834
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 Performance ReportMerging #15834 will not alter performanceComparing Summary
Footnotes
|
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.
I think to avoid a perf hit in enter_expression, you want it to be:
impl<'a> Traverse<'a, TransformState<'a>> for TaggedTemplateTransform<'a, '_> {
// `#[inline]` because this is a hot path and most `Expression`s are not `TaggedTemplateExpression`s,
// so we want this inlined to handle the common case without a function call
#[inline]
fn enter_expression(&mut self, expr: &mut Expression<'a>, ctx: &mut TraverseCtx<'a>) {
if matches!(expr, Expression::TaggedTemplateExpression(_)) {
self.transform_tagged_template(expr, ctx);
}
}
}The idea is that probably 0.01% of Expressions are TaggedTemplateExpressions, so for the common case all you want in the hot path is "Is this a TaggedTemplateExpression? No it's not. Exit." That's a very small function, so it can be inlined, which means no overhead of a function call on the hot path.
|
Another possible improvement (though it doesn't really matter because There are 2 loops at start of
You could merge them into 1 loop by doing the Also the logic for creating let template_arguments = if needs_raw_array {
let raws_argument = /* ... */;
ctx.ast.vec_from_array([cooked_argument, raws_argument])
} else {
ctx.ast.vec1(cooked_argument)
}; |
ff8f872 to
e4487e0
Compare
d973355 to
7c46a9e
Compare
e4487e0 to
2a720db
Compare

Made some improvements based on the suggestions in #15664