swc icon indicating copy to clipboard operation
swc copied to clipboard

Use identical generator transform as `tsc`

Open kdy1 opened this issue 2 years ago • 6 comments

kdy1 avatar Jun 22 '22 16:06 kdy1

Would you mind sharing some details about the reason behind the proposed change?

regenerator-runtime is indeed a bit heavy (2.66 KiB after minified + gzipped), but it is also performant.

Here are some benchmark results I have done last year on Node.js 16.13.1:

image image (This one should be Memory(MiB), not Time(ms))

  • babel: regenerator-runtime used by babel-preset-env
  • fast-async: https://github.com/MatAtBread/fast-async
  • babel-plugin-transform-async-to-promises: https://github.com/rpetrich/babel-plugin-transform-async-to-promises

Benchmark suite: https://github.com/SukkaW/promise-performance-tests

SukkaW avatar Jun 24 '22 02:06 SukkaW

Thank you!

I didn't know the performance difference.

kdy1 avatar Jun 24 '22 02:06 kdy1

I think we should also consider the output size

kdy1 avatar Jun 24 '22 10:06 kdy1

@SukkaW Can you share the code about the benchmark you did? Looks like the Finbonacci one is cirtical but not for others with performance and it takes more memory.

If users are using swc to bundle tiny libs, the 2.66kb might be a issue for bundle size of those libs. We might inline external helpers since they're not too large for the bundle

huozhi avatar Jun 24 '22 10:06 huozhi

@SukkaW Can you share the code about the benchmark you did? Looks like the Finbonacci one is cirtical but not for others with performance and it takes more memory.

Sure! Here is the benchmark suite I forked from V8: https://github.com/SukkaW/promise-performance-tests

And here is the source code of the Fibonacci tests: https://github.com/SukkaW/promise-performance-tests/blob/master/lib/fibonacci-async.js

And here are the outputs:

  • https://github.com/SukkaW/promise-performance-tests/blob/master/build/fibonacci-async-babel.js
  • https://github.com/SukkaW/promise-performance-tests/blob/master/build/fibonacci-async-fast-async.js
  • https://github.com/SukkaW/promise-performance-tests/blob/master/build/fibonacci-async-to-promises.js
  • https://github.com/SukkaW/promise-performance-tests/blob/master/build/fibonacci-async-tsc.js

SukkaW avatar Jun 24 '22 16:06 SukkaW

I tried the tests case and it breaks with some errors such as

ReferenceError: regeneratorRuntime is not defined

I feel this is the major problem that we need to manage polyfill dependencies after compilation, and make those polyfills work. tsc regenerator transform solves this problem. I wouldn't imagine tsc vs babel transform will have huge significant difference in browser as tsc has become the quite popular choice today

huozhi avatar Jul 09 '22 11:07 huozhi

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

swc-bot avatar Oct 16 '22 00:10 swc-bot