Skip to content

Comments

refactor(transformer): share TransformCtx with ref not Rc#6118

Merged
graphite-app[bot] merged 1 commit intomainfrom
09-27-refactor_transformer_share_transformctx_with_ref_not_refcell_
Sep 27, 2024
Merged

refactor(transformer): share TransformCtx with ref not Rc#6118
graphite-app[bot] merged 1 commit intomainfrom
09-27-refactor_transformer_share_transformctx_with_ref_not_refcell_

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Sep 27, 2024

Many transforms share TransformCtx. Currently it's shared with Rc, which has a cost as the Rc has to be cloned many times, and it also makes dropping Transformer more expensive.

The PR changes that to share it as a normal reference &TransformCtx instead.

This requires adding an inner TransformerImpl. Transformer is now just a facade which creates the TransformCtx and stores options. Transformer::build_with_symbols_and_scopes constructs TransformerImpl and runs the visitor on it.

Unlikely to have any perf impact on larger files, but for small files where setup/teardown is a larger % of the overall workload, it may help a little.

@graphite-app
Copy link
Contributor

graphite-app bot commented Sep 27, 2024

Your org has enabled the Graphite merge queue for merging into main

Add the label “0-merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @overlookmotel and the rest of your teammates on Graphite Graphite

@github-actions github-actions bot added the A-transformer Area - Transformer / Transpiler label Sep 27, 2024
@overlookmotel overlookmotel marked this pull request as ready for review September 27, 2024 16:31
@codspeed-hq
Copy link

codspeed-hq bot commented Sep 27, 2024

CodSpeed Performance Report

Merging #6118 will improve performances by 6.66%

Comparing 09-27-refactor_transformer_share_transformctx_with_ref_not_refcell_ (09e41c2) with main (58fd6eb)

Summary

⚡ 3 improvements
✅ 26 untouched benchmarks

Benchmarks breakdown

Benchmark main 09-27-refactor_transformer_share_transformctx_with_ref_not_refcell_ Change
transformer[antd.js] 51.5 ms 48.9 ms +5.2%
transformer[checker.ts] 20.7 ms 19.4 ms +6.66%
transformer[pdf.mjs] 7.7 ms 7.3 ms +5.98%

@overlookmotel overlookmotel changed the title refactor(transformer): share TransformCtx with ref not RefCell refactor(transformer): share TransformCtx with ref not Rc Sep 27, 2024
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Sep 27, 2024
@graphite-app
Copy link
Contributor

graphite-app bot commented Sep 27, 2024

Merge activity

  • Sep 27, 2:07 PM EDT: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Sep 27, 2:07 PM EDT: Boshen added this pull request to the Graphite merge queue.
  • Sep 27, 2:12 PM EDT: Boshen merged this pull request with the Graphite merge queue.

Many transforms share `TransformCtx`. Currently it's shared with `Rc`, which has a cost as the `Rc` has to be cloned many times, and it also makes dropping `Transformer` more expensive.

The PR changes that to share it as a normal reference `&TransformCtx` instead.

This requires adding an inner `TransformerImpl`. `Transformer` is now just a facade which creates the `TransformCtx` and stores options. `Transformer::build_with_symbols_and_scopes` constructs `TransformerImpl` and runs the visitor on it.

Unlikely to have any perf impact on larger files, but for small files where setup/teardown is a larger % of the overall workload, it may help a little.
@Boshen Boshen force-pushed the 09-27-refactor_transformer_share_transformctx_with_ref_not_refcell_ branch from c1801ef to 09e41c2 Compare September 27, 2024 18:07
@graphite-app graphite-app bot merged commit 09e41c2 into main Sep 27, 2024
@graphite-app graphite-app bot deleted the 09-27-refactor_transformer_share_transformctx_with_ref_not_refcell_ branch September 27, 2024 18:12
@overlookmotel
Copy link
Member Author

Just for the record, the large perf boost in this PR is not really related to the main thrust of the PR. It's all down to an unrelated change which got into this PR - adding #[inline] to enter_expression.

The change of replacing Rc with & doesn't affect any of the benchmarks for large files, but it looks like it gave a 1%-2% speed-up on the small RadixUIAdoptionSection.jsx benchmark - because setup and teardown is a larger proportion of the overall workload for small files.

Boshen pushed a commit that referenced this pull request Sep 27, 2024
…6121)

Similar to #6118.

Share `TypeScriptOptions` between transforms as a plain `&` reference, rather than an `Rc`, to reduce setup/teardown time.

The code to parse pragmas from comments is moved into `Transformer::new`. This isn't the ideal place for it, but it means `TypeScriptOptions` can be shared with the existing `'ctx` lifetime, rather than having to have a 3rd lifetime `TypeScript<'a, 'ctx, 'options>`.
Boshen added a commit that referenced this pull request Sep 28, 2024
## [0.30.4] - 2024-09-28

### Bug Fixes

- 8582ae3 codegen: Missing parentheses if there is a pure comment before
a NewExpression as a ComputedMemberExpression's callee (#6105) (Dunqing)
- fd6798f parser: Remove unintended `pub Kind` (#6109) (Boshen)
- 6f98aad sourcemap: Align sourcemap type with Rollup (#6133) (Boshen)
- 64d4756 transformer: Fix debug assertion in `Stack` (#6106)
(overlookmotel)

### Performance

- 05852a0 codegen: Do not check whether there are annotation comments or
not if we don't preserve annotation comments (#6107) (Dunqing)

### Documentation

- 26a273a oxc-transform: Update README (Boshen)
- e2c5baf transformer: Fix formatting of README (#6111) (overlookmotel)

### Refactor

- 2090fce semantic: Fix lint warning in nightly (#6110) (overlookmotel)
- 7bc3988 transformer: Remove dead code (#6124) (overlookmotel)
- 07fe45b transformer: Exponentiation operator: convert to match (#6123)
(overlookmotel)
- 4387845 transformer: Share `TypeScriptOptions` with ref not `Rc`
(#6121) (overlookmotel)
- 09e41c2 transformer: Share `TransformCtx` with ref not `Rc` (#6118)
(overlookmotel)
- 58fd6eb transformer: Pre-allocate more stack space (#6095)
(overlookmotel)
- 9ac80bd transformer: Add wrapper around `NonNull` (#6115)
(overlookmotel)
- c50500e transformer: Move common stack functionality into
`StackCommon` trait (#6114) (overlookmotel)
- 9839059 transformer: Simplify `StackCapacity` trait (#6113)
(overlookmotel)

---------

Co-authored-by: Boshen <[email protected]>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants