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): pre-allocate more stack space #6095

Merged

Conversation

overlookmotel
Copy link
Collaborator

@overlookmotel overlookmotel commented Sep 26, 2024

Pre-allocate 16 bytes for stacks in transforms that use them. Allocators usually support minimum of 16 bytes for allocations anyway. Now that we're using SparseStack, allocating decent capacity is now cheap.

Copy link

graphite-app bot commented Sep 26, 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.

@github-actions github-actions bot added the A-transformer Area - Transformer / Transpiler label Sep 26, 2024
@overlookmotel overlookmotel marked this pull request as ready for review September 27, 2024 00:00
@overlookmotel
Copy link
Collaborator Author

This stack of PRs introducing NonEmptyStack and Stack has minimal perf impact (about +0.5% in total).

But we can also use these more efficient stack structures in many other places in our codebase, so the impact will be more significant in aggregate, especially for stacks which get pretty deep e.g. TraverseAncestry.

Copy link

codspeed-hq bot commented Sep 27, 2024

CodSpeed Performance Report

Merging #6095 will not alter performance

Comparing 09-27-refactor_transformer_pre-allocate_more_stack_space (58fd6eb) with main (c519182)

Summary

✅ 29 untouched benchmarks

@Dunqing Dunqing added the 0-merge Merge with Graphite Merge Queue label Sep 27, 2024
Copy link

graphite-app bot commented Sep 27, 2024

Merge activity

  • Sep 27, 12:28 AM 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, 12:28 AM EDT: Dunqing added this pull request to the Graphite merge queue.
  • Sep 27, 12:46 AM EDT: The Graphite merge queue couldn't merge this PR because it failed for an unknown reason (All comments must be resolved before merging).
  • Sep 27, 1:49 AM 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, 9:42 AM EDT: The merge label '0-merge' was removed. This PR will no longer be merged by the Graphite merge queue
  • Sep 27, 12:48 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, 12:48 PM EDT: Boshen added this pull request to the Graphite merge queue.
  • Sep 27, 1:07 PM EDT: Boshen merged this pull request with the Graphite merge queue.

@Dunqing Dunqing force-pushed the 09-24-refactor_transformer_add_sparsestack_with_capacity_method branch from e1a6472 to e60ce50 Compare September 27, 2024 04:31
Dunqing pushed a commit that referenced this pull request Sep 27, 2024
Pre-allocate 16 bytes for stacks in transforms that use them. Allocators usually support minimum of 16 bytes for allocations anyway. Now that we're using `SparseStack`, allocating decent capacity is now cheap.
@Dunqing Dunqing force-pushed the 09-27-refactor_transformer_pre-allocate_more_stack_space branch from f2a5883 to f191fb3 Compare September 27, 2024 04:32
crates/oxc_transformer/src/es2015/arrow_functions.rs Outdated Show resolved Hide resolved
Base automatically changed from 09-24-refactor_transformer_add_sparsestack_with_capacity_method to main September 27, 2024 04:44
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Sep 27, 2024
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Sep 27, 2024
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.

FYI previous PR crashed somewhere https://github.com/oxc-project/monitor-oxc/actions/runs/11065170732/job/30744171583

Running Transformer.
thread 'main' panicked at /home/runner/work/monitor-oxc/oxc/crates/oxc_transformer/src/helpers/stack/standard.rs:341:9:
assertion failed: self.cursor < self.end

Boshen pushed a commit that referenced this pull request Sep 27, 2024
Fix incorrect debug assertion in `Stack`. The code itself was fine, but debug assertion was testing the wrong thing.

This error was spotted by @Boshen: #6095 (review)

Also add more debug asserts and change test so it fails before the fix in this PR.
overlookmotel added a commit that referenced this pull request Sep 27, 2024
Pre-allocate 16 bytes for stacks in transforms that use them. Allocators usually support minimum of 16 bytes for allocations anyway. Now that we're using `SparseStack`, allocating decent capacity is now cheap.
@overlookmotel overlookmotel force-pushed the 09-27-refactor_transformer_pre-allocate_more_stack_space branch from f191fb3 to 8146517 Compare September 27, 2024 13:40
@overlookmotel overlookmotel changed the base branch from main to 09-27-refactor_transformer_add_wrapper_around_nonnull_ September 27, 2024 13:40
@overlookmotel overlookmotel removed the 0-merge Merge with Graphite Merge Queue label Sep 27, 2024
@overlookmotel overlookmotel force-pushed the 09-27-refactor_transformer_add_wrapper_around_nonnull_ branch from 6a68db0 to ea6c125 Compare September 27, 2024 13:54
overlookmotel added a commit that referenced this pull request Sep 27, 2024
Pre-allocate 16 bytes for stacks in transforms that use them. Allocators usually support minimum of 16 bytes for allocations anyway. Now that we're using `SparseStack`, allocating decent capacity is now cheap.
@overlookmotel overlookmotel force-pushed the 09-27-refactor_transformer_pre-allocate_more_stack_space branch from 8146517 to e0f3c64 Compare September 27, 2024 13:54
@overlookmotel overlookmotel dismissed Dunqing’s stale review September 27, 2024 14:20

The change is now made.

@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Sep 27, 2024
Pre-allocate 16 bytes for stacks in transforms that use them. Allocators usually support minimum of 16 bytes for allocations anyway. Now that we're using `SparseStack`, allocating decent capacity is now cheap.
@Boshen Boshen force-pushed the 09-27-refactor_transformer_add_wrapper_around_nonnull_ branch from ea6c125 to 9ac80bd Compare September 27, 2024 16:49
@Boshen Boshen force-pushed the 09-27-refactor_transformer_pre-allocate_more_stack_space branch from e0f3c64 to 58fd6eb Compare September 27, 2024 16:50
Base automatically changed from 09-27-refactor_transformer_add_wrapper_around_nonnull_ to main September 27, 2024 17:05
@graphite-app graphite-app bot merged commit 58fd6eb into main Sep 27, 2024
27 checks passed
@graphite-app graphite-app bot deleted the 09-27-refactor_transformer_pre-allocate_more_stack_space branch September 27, 2024 17:07
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 <1430279+Boshen@users.noreply.github.com>
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.

3 participants