Skip to content

perf(transformer/tagged-template): add #[cold] hint to unlikely path#18034

Merged
graphite-app[bot] merged 1 commit intomainfrom
om/01-15-perf_transformer_tagged-template_add_cold_hint_to_unlikely_path
Jan 15, 2026
Merged

perf(transformer/tagged-template): add #[cold] hint to unlikely path#18034
graphite-app[bot] merged 1 commit intomainfrom
om/01-15-perf_transformer_tagged-template_add_cold_hint_to_unlikely_path

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Jan 15, 2026

Follow-on after #15834. Tiny perf optimization. Tagged template literals are pretty rare. Add #[cold] attr to transform_tagged_template to hint to compiler that the branch for "yes, it's a tagged template" in enter_expression is unlikely to be taken. This should make the compiler make "not a tagged template" the default path.

@github-actions github-actions bot added A-transformer Area - Transformer / Transpiler C-performance Category - Solution not expected to change functional behavior, only performance labels Jan 15, 2026
Copy link
Member Author

overlookmotel commented Jan 15, 2026


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

@overlookmotel overlookmotel marked this pull request as ready for review January 15, 2026 12:57
Copilot AI review requested due to automatic review settings January 15, 2026 12:57
@codspeed-hq
Copy link

codspeed-hq bot commented Jan 15, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing om/01-15-perf_transformer_tagged-template_add_cold_hint_to_unlikely_path (d6236f7) with om/01-15-refactor_transformer_tagged-template_reformat_comment (70541d6)

Summary

✅ 38 untouched benchmarks
⏩ 7 skipped benchmarks1

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a #[cold] attribute to the transform_tagged_template method to optimize performance by hinting to the compiler that tagged template expressions are rare. This allows the compiler to optimize the common path (non-tagged templates) in the enter_expression method.

Changes:

  • Added #[cold] attribute to transform_tagged_template method with an explanatory comment

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@overlookmotel
Copy link
Member Author

@Dunqing Apologies for the stack of nits. I just thought I'd split it into multiple PRs so it's easy to see what each change does. Hopefully we won't have to touch this transform again for a long time, so I thought might as well make these changes now, and get it done with!

@Dunqing
Copy link
Member

Dunqing commented Jan 15, 2026

Is it okay in a CSS-in-JS project? That would be common rather than rare, I think, but still less in terms of Expression.

@Dunqing
Copy link
Member

Dunqing commented Jan 15, 2026

@Dunqing Apologies for the stack of nits. I just thought I'd split it into multiple PRs so it's easy to see what each change does. Hopefully we won't have to touch this transform again for a long time, so I thought might as well make these changes now, and get it done with!

No worries!

Copy link
Member

@Dunqing Dunqing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to merge if you think it is good!

@overlookmotel
Copy link
Member Author

overlookmotel commented Jan 15, 2026

Is it okay in a CSS-in-JS project? That would be common rather than rare, I think, but still less in terms of Expression.

I suspect that even in a CSS-in-JS project, other expressions like x = y, x == y, x || y, () => x will outnumber the tagged template literals. But anyway this PR only adds #[cold] attr - meaning "this branch is less likely than the other one". I didn't also add #[inline(never)] which is the one which says "this branch is really rare".

#[cold] attr is really unergonomic. I wish Rust would get on with making likely() and unlikely() stable. They're much easier to use and the meaning is clearer. But only on nightly! https://doc.rust-lang.org/nightly/std/hint/fn.unlikely.html

@overlookmotel overlookmotel added the 0-merge Merge with Graphite Merge Queue label Jan 15, 2026
Copy link
Member Author

overlookmotel commented Jan 15, 2026

Merge activity

@overlookmotel
Copy link
Member Author

Feel free to merge if you think it is good!

Well to be honest I don't think it makes much difference either way. But I don't think it's bad, so merging.

#18034)

Follow-on after #15834. Tiny perf optimization. Tagged template literals are pretty rare. Add `#[cold]` attr to `transform_tagged_template` to hint to compiler that the branch for "yes, it's a tagged template" in `enter_expression` is unlikely to be taken. This should make the compiler make "not a tagged template" the default path.
@graphite-app graphite-app bot force-pushed the om/01-15-refactor_transformer_tagged-template_reformat_comment branch from 70541d6 to 04f8379 Compare January 15, 2026 13:47
@graphite-app graphite-app bot force-pushed the om/01-15-perf_transformer_tagged-template_add_cold_hint_to_unlikely_path branch from d6236f7 to 8ee6f80 Compare January 15, 2026 13:48
@Dunqing
Copy link
Member

Dunqing commented Jan 15, 2026

#[cold] attr is really unergonomic. I wish Rust would get on with making likely() and unlikely() stable. They're much easier to use and the meaning is clearer. But only on nightly! https://doc.rust-lang.org/nightly/std/hint/fn.unlikely.html

TIL, thank you!

@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Jan 15, 2026
Base automatically changed from om/01-15-refactor_transformer_tagged-template_reformat_comment to main January 15, 2026 13:54
@graphite-app graphite-app bot merged commit 8ee6f80 into main Jan 15, 2026
22 checks passed
@graphite-app graphite-app bot deleted the om/01-15-perf_transformer_tagged-template_add_cold_hint_to_unlikely_path branch January 15, 2026 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-transformer Area - Transformer / Transpiler C-performance Category - Solution not expected to change functional behavior, only performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants