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

Wasm #691

Merged
merged 27 commits into from
May 7, 2020
Merged

Wasm #691

merged 27 commits into from
May 7, 2020

Conversation

kdy1
Copy link
Member

@kdy1 kdy1 commented Feb 26, 2020

I've managed to implement transformSyncand trasnformFileSync within a wasm module.
Currently, it does not have same api as @swc/core and only two methods are implemented.

Benchmark result

(Note: es2015 = es5 as there's no compiler pass to convert es2015 code to es5 code)

[transform]
  swc (es3) x 391 ops/sec ±2.03% (62 runs sampled)
  swc-wasm (es3) x 94.30 ops/sec ±11.77% (65 runs sampled)
  swc (es2015) x 623 ops/sec ±0.65% (86 runs sampled)
  swc-wasm (es2015) x 151 ops/sec ±0.45% (81 runs sampled)
  swc (es2016) x 1,768 ops/sec ±0.96% (88 runs sampled)
  swc-wasm (es2016) x 526 ops/sec ±0.60% (88 runs sampled)
  swc (es2017) x 1,778 ops/sec ±0.57% (89 runs sampled)
  swc-wasm (es2017) x 535 ops/sec ±0.54% (86 runs sampled)
  swc (es2018) x 2,363 ops/sec ±1.34% (89 runs sampled)
  swc-wasm (es2018) x 745 ops/sec ±0.62% (87 runs sampled)
  swc-optimize (es3) x 543 ops/sec ±0.59% (87 runs sampled)
  babel (es5) x 35.56 ops/sec ±5.80% (53 runs sampled)

It's 3 ~ 4 times slower than the prebuilt binary.

Btw, I'm not sure about the way to implement async apis.

@kdy1 kdy1 mentioned this pull request Feb 26, 2020
@vovacodes
Copy link
Contributor

Please land this PR, it's such a game-changer!

@kdy1
Copy link
Member Author

kdy1 commented May 5, 2020

@vovaguguiev Can you tell me your usecase? I think x3 slowdown is not a simple issue.

Note: As typical usage of swc involves multiple promises, swc is 60+ times faster than babel.
However, wasm version does not support such threading. So it's only 6x times faster than babel.

@vovacodes
Copy link
Contributor

I would like to use it in a Cloudflare Worker, the options I have there are either JS or WASM. Even 5x speed up comparing to Babel is a great improvement for my use case because of workers’ limits on CPU time per request (50ms)

@vovacodes
Copy link
Contributor

The alternative I am exploring right now is to try and use swc directly from rust code that I compile to wasm, I could write a custom transformation, that I need, directly in Rust similar to how transform-react and other are implemented. Do you think it’s a viable option?

@kdy1
Copy link
Member Author

kdy1 commented May 5, 2020

@vovaguguiev Oh... Fair point.
I forgot environments where native binaries are restricted.
I'll start working on this right now.

@kdy1
Copy link
Member Author

kdy1 commented May 5, 2020

@vovaguguiev I'm pinging you because it's almost done.

I only implemented transformSync, parseSync and printSync at the moment. Is it enough for your use case?

I couldn't make apis related to file because wasm does not support it and I'm not sure if threading is supported in wasm.

@vovacodes
Copy link
Contributor

@kdy1 Thanks a lot! I think sync versions are enough for my case. Look forward to trying it!

@kdy1 kdy1 merged commit 14f5212 into swc-project:master May 7, 2020
@kdy1 kdy1 deleted the wasm branch May 7, 2020 09:45
@kdy1
Copy link
Member Author

kdy1 commented May 7, 2020

Published @swc/wasm@0.1.0

@whatnickcodes
Copy link

whatnickcodes commented Feb 26, 2021

@vovacodes did you ever see success with this in a Cloudflare worker? Curious to know what kind of performance you saw / the use case you had?

@swc-project swc-project locked as resolved and limited conversation to collaborators Nov 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants