Skip to content

Comments

refactor(transformer): pass Rcs by value#3550

Merged
graphite-app[bot] merged 1 commit intomainfrom
06-06-refactor_transformer_pass_rc_s_by_value
Jun 6, 2024
Merged

refactor(transformer): pass Rcs by value#3550
graphite-app[bot] merged 1 commit intomainfrom
06-06-refactor_transformer_pass_rc_s_by_value

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Jun 6, 2024

Rc<T> is already a pointer, so passing &Rc<T> to functions adds unnecessary indirection (reference to a reference).

@graphite-app
Copy link
Contributor

graphite-app bot commented Jun 6, 2024

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

Add the label “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.

@github-actions github-actions bot added the A-transformer Area - Transformer / Transpiler label Jun 6, 2024
@overlookmotel overlookmotel marked this pull request as ready for review June 6, 2024 00:49
@codspeed-hq
Copy link

codspeed-hq bot commented Jun 6, 2024

CodSpeed Performance Report

Merging #3550 will not alter performance

Comparing 06-06-refactor_transformer_pass_rc_s_by_value (0948124) with main (6506d08)

Summary

✅ 22 untouched benchmarks

@overlookmotel overlookmotel force-pushed the 06-06-refactor_transformer_pass_rc_s_by_value branch 2 times, most recently from 270cc78 to 3b78266 Compare June 6, 2024 01:16
@overlookmotel
Copy link
Member Author

overlookmotel commented Jun 6, 2024

I think the 6% perf regression CodSpeed is reporting on one benchmark is specious - transformer runs semantic, so the noisy benchmark problem that semantic has now affects the transformer as well.

Have force pushed to run the benchmarks again.

@overlookmotel
Copy link
Member Author

Yup. Re-ran it and the regression went away. Maddening!

@graphite-app
Copy link
Contributor

graphite-app bot commented Jun 6, 2024

Merge activity

`Rc<T>` is already a pointer, so passing `&Rc<T>` to functions adds unnecessary indirection (reference to a reference).
@Dunqing Dunqing force-pushed the 06-06-fix_transformer_correct_spans_for_jsx_transform branch from 8c5a4bb to 7982b93 Compare June 6, 2024 03:22
@Dunqing Dunqing force-pushed the 06-06-refactor_transformer_pass_rc_s_by_value branch from 3b78266 to 0948124 Compare June 6, 2024 03:23
@Dunqing Dunqing changed the base branch from 06-06-fix_transformer_correct_spans_for_jsx_transform to main June 6, 2024 03:30
@graphite-app graphite-app bot merged commit 0948124 into main Jun 6, 2024
@graphite-app graphite-app bot deleted the 06-06-refactor_transformer_pass_rc_s_by_value branch June 6, 2024 03:31
This was referenced Jun 6, 2024
Boshen pushed a commit that referenced this pull request Jun 6, 2024
Similar to #3550. Avoid cloning an `Rc` in one place and pass `Rc`s as
values not references in others.
@github-actions github-actions bot mentioned this pull request Jun 7, 2024
Boshen added a commit that referenced this pull request Jun 7, 2024
## [0.13.4] - 2024-06-07

### Features

- 5c8e16c coverage: Second transformer build does not print typescript
(#3561) (Dunqing)
- 646b993 coverage/transformer: Handle @jsx option (#3553) (Dunqing)
- a939ddd transformer/typescript: Remove more typescript ast nodes
(#3563) (Dunqing)
- e8a20f8 transformer/typescript: Remove typescript ast nodes (#3559)
(Dunqing)
- ee9a215 transformer/typescript: Handle namespace directive correctly
(#3532) (Dunqing)

### Bug Fixes

- affb2c8 codegen: Print indentation before directive (#3512) (Dunqing)
- f6939cb transformer: Store `react_importer` in `Bindings` in JSX
transform (#3551) (overlookmotel)
- 7982b93 transformer: Correct spans for JSX transform (#3549)
(overlookmotel)
- c00598b transformer: JSX set `reference_id` on refs to imports (#3524)
(overlookmotel)

### Performance

- 37cdc13 transformer: Faster checks if JSX plugin enabled (#3577)
(overlookmotel)
- 9f467b8 transformer: Avoid fragment update where possible (#3535)
(overlookmotel)
- ac394f0 transformer: JSX parse pragma only once (#3534)
(overlookmotel)

### Documentation

- 1d3c0d7 span: Add doc comments to `oxc_span::Span` (#3543) (Don Isaac)

### Refactor

- f2113ae transformer: Reduce cloning and referencing `Rc`s (#3576)
(overlookmotel)
- 0948124 transformer: Pass `Rc`s by value (#3550) (overlookmotel)
- e4d74ac transformer: Remove `update_fragment` from JSX transform
(#3541) (overlookmotel)
- 73b7864 transformer: Combine import and usage in JSX transform (#3540)
(overlookmotel)
- 6978269 transformer/typescript: Replace reference collector with
symbols references (#3533) (Dunqing)

Co-authored-by: Boshen <[email protected]>
Boshen pushed a commit that referenced this pull request Jun 8, 2024
Same as #3550.

`Rc<T>` is already a reference, so instead of passing an `&Rc<T>` to a function and then `Rc::clone()` it in the function, it's better to clone it first and pass `Rc<T>` to the function.

`Rc<T>` and `&Rc<T>` are both 8 bytes, so it introduces no additional overhead to the function call, and reduces indirection.

This is a very small optimization. Am only submitting these changes for purpose of code tidying - making the patterns around `Rc` consistent and optimal throughout the codebase.

We should probably look if we can remove some of these `Rc`s entirely and replace them with plain `&` refs. I suspect `Rc` is not actually required in most places and we're only using it to avoid dealing with lifetimes, but it's sub-optimal as `Rc::clone` has a cost, whereas copying a `&` ref has none.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-transformer Area - Transformer / Transpiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants