Skip to content
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

refactor(transformer/jsx): simplify and remove all AstBuilder::copy usages #9209

Conversation

Dunqing
Copy link
Member

@Dunqing Dunqing commented Feb 18, 2025

This PR aims to remove all AstBuilder::copy and simplify some code.

Copy link
Member Author

Dunqing commented Feb 18, 2025


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.

@github-actions github-actions bot added A-transformer Area - Transformer / Transpiler C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels Feb 18, 2025
Copy link

codspeed-hq bot commented Feb 18, 2025

CodSpeed Performance Report

Merging #9209 will improve performances by 4.45%

Comparing 02-18-refactor_transformer_jsx_simplify_and_remove_all_astbuilder_copy_usages (558ed8b) with main (542bbd7)

Summary

⚡ 3 improvements
✅ 30 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
transformer[antd.js] 55.3 ms 53.2 ms +3.85%
transformer[checker.ts] 25 ms 24 ms +4.45%
transformer[pdf.mjs] 11 ms 10.6 ms +3.93%

Copy link
Member

@Boshen Boshen left a comment

Choose a reason for hiding this comment

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

Legend!

@Boshen
Copy link
Member

Boshen commented Feb 18, 2025

Merging #9209 will improve performances by 4.46%

wat?!

@Dunqing
Copy link
Member Author

Dunqing commented Feb 18, 2025

Merging #9209 will improve performances by 4.46%

wat?!

It is probably related to I added a #[inline] to exit_expression.

Copy link
Contributor

@overlookmotel overlookmotel left a comment

Choose a reason for hiding this comment

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

I've got say, this is masterful!

I had not considered taking ownership of the node at the very start, so when I tried to make this change, I got tied up with needing &mut references everywhere, and it became a hot mess. This is a really clean and simple solution. Very nice.

Additionally... Every method takes only small types as its params (ArenaBox or a 16-byte enum).

4.5% perf boost.

AND you killed the dreaded AstBuilder::copy!

Merge it merge it merge it!

@overlookmotel overlookmotel added the 0-merge Merge with Graphite Merge Queue label Feb 18, 2025
Copy link
Contributor

overlookmotel commented Feb 18, 2025

Merge activity

  • Feb 18, 3:10 PM EST: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Feb 18, 3:10 PM EST: A user added this pull request to the Graphite merge queue.
  • Feb 18, 3:15 PM EST: A user merged this pull request with the Graphite merge queue.

… usages (#9209)

This PR aims to remove all `AstBuilder::copy` and simplify some code.
@graphite-app graphite-app bot force-pushed the 02-18-refactor_transformer_jsx_simplify_and_remove_all_astbuilder_copy_usages branch from 454a568 to 558ed8b Compare February 18, 2025 20:10
@overlookmotel
Copy link
Contributor

It is probably related to I added a #[inline] to exit_expression.

Yes, likely it was that. We should take a look at the TS transforms and see if we can get a quick win from #[inline] on those hot visitor methods. We (you) wrote those transforms before we'd discovered the importance of inlining in the transformer.

@graphite-app graphite-app bot merged commit 558ed8b into main Feb 18, 2025
25 checks passed
@graphite-app graphite-app bot deleted the 02-18-refactor_transformer_jsx_simplify_and_remove_all_astbuilder_copy_usages branch February 18, 2025 20:15
graphite-app bot pushed a commit that referenced this pull request Feb 19, 2025
…er` rather than `drain` (#9216)

This change I forgot to do this in #9209, In the case of owning `Vec`, we do not need to obtain the value owner through `drain` but `into_iter`.

The diff in this PR is hard to diff. My purpose is to change `drain` to `into_iter`, other changes are for solving the borrow check and keeping the same output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0-merge Merge with Graphite Merge Queue A-transformer Area - Transformer / Transpiler C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants