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

Avoid dynamic dispatch when calling wrapCheck #16060

Merged
merged 4 commits into from Oct 25, 2023

Conversation

yepitschunked
Copy link
Contributor

@yepitschunked yepitschunked commented Oct 24, 2023

Q                       A
Fixed Issues? N/A
Patch: Bug Fix? Yes
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

Micro-optimization to avoid dynamic function dispatch in wrapCheck, which is in the hot path of babel transforms. The current code interpolates a string and looks up a function at runtime during every visitor function invocation, whereas this PR looks up the function once while building the visitor and just calls it during visitor function invocation.

I couldn't find any docs on babel benchmarking, so I used swc's benchmark and modified it to only run babel. Here are the before/after results:

Before:

[es3] Running single thread benchmarks
babel (preset-env) x 149 ops/sec ±2.92% (79 runs sampled)
[es3] Transform rxjs/Observable.ts benchmark bench suite: Fastest is babel (preset-env)
[es5] Running single thread benchmarks
babel (preset-env) x 159 ops/sec ±2.71% (83 runs sampled)
[es5] Transform rxjs/Observable.ts benchmark bench suite: Fastest is babel (preset-env)
[es2015] Running single thread benchmarks
babel (preset-env) x 162 ops/sec ±2.29% (76 runs sampled)
[es2015] Transform rxjs/Observable.ts benchmark bench suite: Fastest is babel (preset-env)
[es2016] Running single thread benchmarks
babel (preset-env) x 163 ops/sec ±2.24% (77 runs sampled)
[es2016] Transform rxjs/Observable.ts benchmark bench suite: Fastest is babel (preset-env)
[es2017] Running single thread benchmarks
babel (preset-env) x 162 ops/sec ±2.77% (84 runs sampled)
[es2017] Transform rxjs/Observable.ts benchmark bench suite: Fastest is babel (preset-env)
[es2018] Running single thread benchmarks
babel (preset-env) x 162 ops/sec ±2.78% (84 runs sampled)
[es2018] Transform rxjs/Observable.ts benchmark bench suite: Fastest is babel (preset-env)
[es2019] Running single thread benchmarks
babel (preset-env) x 161 ops/sec ±2.56% (84 runs sampled)
[es2019] Transform rxjs/Observable.ts benchmark bench suite: Fastest is babel (preset-env)
[es2020] Running single thread benchmarks
babel (preset-env) x 163 ops/sec ±2.25% (84 runs sampled)
[es2020] Transform rxjs/Observable.ts benchmark bench suite: Fastest is babel (preset-env)

After:

[es3] Running single thread benchmarks
babel (preset-env) x 160 ops/sec ±3.17% (83 runs sampled)
[es3] Transform rxjs/Observable.ts benchmark bench suite: Fastest is babel (preset-env)
[es5] Running single thread benchmarks
babel (preset-env) x 169 ops/sec ±2.78% (79 runs sampled)
[es5] Transform rxjs/Observable.ts benchmark bench suite: Fastest is babel (preset-env)
[es2015] Running single thread benchmarks
babel (preset-env) x 171 ops/sec ±2.28% (81 runs sampled)
[es2015] Transform rxjs/Observable.ts benchmark bench suite: Fastest is babel (preset-env)
[es2016] Running single thread benchmarks
babel (preset-env) x 170 ops/sec ±2.96% (81 runs sampled)
[es2016] Transform rxjs/Observable.ts benchmark bench suite: Fastest is babel (preset-env)
[es2017] Running single thread benchmarks
babel (preset-env) x 171 ops/sec ±2.88% (81 runs sampled)
[es2017] Transform rxjs/Observable.ts benchmark bench suite: Fastest is babel (preset-env)
[es2018] Running single thread benchmarks
babel (preset-env) x 173 ops/sec ±2.61% (82 runs sampled)
[es2018] Transform rxjs/Observable.ts benchmark bench suite: Fastest is babel (preset-env)
[es2019] Running single thread benchmarks
babel (preset-env) x 173 ops/sec ±2.37% (81 runs sampled)
[es2019] Transform rxjs/Observable.ts benchmark bench suite: Fastest is babel (preset-env)
[es2020] Running single thread benchmarks
babel (preset-env) x 171 ops/sec ±2.53% (81 runs sampled)
[es2020] Transform rxjs/Observable.ts benchmark bench suite: Fastest is babel (preset-env)

It's roughly a 5-6% improvement.

@yepitschunked yepitschunked marked this pull request as ready for review October 24, 2023 23:28
Copy link
Contributor

@JLHwung JLHwung left a comment

Choose a reason for hiding this comment

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

Thanks!

@JLHwung JLHwung added the PR: Performance 🏃‍♀️ A type of pull request used for our changelog categories label Oct 25, 2023
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

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

Thank you!

@nicolo-ribaudo nicolo-ribaudo merged commit 4fb4fa6 into babel:main Oct 25, 2023
45 checks passed
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jan 25, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: traverse PR: Performance 🏃‍♀️ A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants