Giter Site home page Giter Site logo

wasm? about swc HOT 18 CLOSED

swc-project avatar swc-project commented on May 7, 2024 13
wasm?

from swc.

Comments (18)

anurbol avatar anurbol commented on May 7, 2024 5

Hey people, SWC Parser can be built for Wasm! If someone needs, I think, you could make the whole SWC project Wasm-compatible easy enough. So when you build for Wasm you'd likely see the inconsistent resolution for an import error. To fix that, you should get rid of dependency renaming in Cargo.toml files across the whole SWC project. Example is here

from swc.

anurbol avatar anurbol commented on May 7, 2024 2

@kdy1 Hey, I've managed to compile the Parser (nothing more) with --target wasm32-unknown-unknown! It turns out that dependency renaming is broken for the Wasm target. Therefore I did this...
In ecmascript\parser\Cargo.toml
Changed this:

ast = { package = "swc_ecma_ast", version = "0.10.0", path ="../ast" }
parser_macros = { package = "swc_ecma_parser_macros", version = "0.4", path ="./macros" }

...to this...

swc_ecma_ast = { version = "0.10.0", path ="../ast" }
swc_ecma_parser_macros = { package = "swc_ecma_parser_macros", version = "0.4", path ="./macros" }

...and minor things, including replacements throughout the swc_ecma_parser crate.

Is it OK? Are the new names OK? Can I make a pull request?

BTW this project is incredible, I am your fan, are you even a human? Because humans can't do such amount of work 😄

from swc.

kdy1 avatar kdy1 commented on May 7, 2024 2

I've implemented transformSync and transformFileSync. It seems like wasm is 3 ~ 4 times slower than native binary.

Please tell me if is it ok. If it's ok, I'll implement other methods for wasm and make it fallback for the swc.

I uploaded the benchmark result at:: #691

from swc.

alubbe avatar alubbe commented on May 7, 2024 1

Came here to further express my interest in a wasm release. If the performance is roughly similar, then I believe going wasm would be a tremendous boost to the reach and usage of swc because it suddenly works on every modern browser, every modern version of node and on every operating system that v8 supports - without needing to configure a build system or pre-building binaries.

Personally, I think a great way to continue the discussion would be for @anurbol to contribute his work as a PR and then discuss the feasibility of the changes and measure the performance impact. Happy to help out!

from swc.

kdy1 avatar kdy1 commented on May 7, 2024 1

#691 Is merged. Closing. Please comment or file a new issue if it's not enough.

from swc.

dennythecoder avatar dennythecoder commented on May 7, 2024

You may want to check out #87

from swc.

anurbol avatar anurbol commented on May 7, 2024

@kdy1 Continuing #87 (comment)... So what are those cfgs to build a wasm binary? I've tried to build only the Parser for WASM and got this error I am not sure if it relates to SWC or to Rust. Do you have any clues?

from swc.

kdy1 avatar kdy1 commented on May 7, 2024

@anurbol

So what are those cfgs to build a wasm binary?

#[cfg] should be placed on some structs in swc_common. Other codes do not use os-specific features.

got this error I am not sure if it relates to SWC or to Rust. Do you have any clues?

I think it's rustc's bug related to wasm target. I'm not sure about the way to fix it.

from swc.

kdy1 avatar kdy1 commented on May 7, 2024

@anurbol I'll be happy with a such PR. Thank you for the interest on swc!

from swc.

3cp avatar 3cp commented on May 7, 2024

I would love to see a swc wasm release. Even a separated npm package name is fine.

I am using babel and tsc in both nodejs and browser env. But they are both too slow and consume too much memory for my taste.

Very interested on swc!

from swc.

anurbol avatar anurbol commented on May 7, 2024

@alubbe I have already contributed a very simple PR that restored Wasm support for SWC Parser alone. Yes, the whole SWC-Project is WASM-ready, mostly, just some configuration files should be fixed. Regarding performance impact, in my case WASM was 2 to 3 times slower than native binary, but still this is like x30 times faster than JS.

from swc.

alubbe avatar alubbe commented on May 7, 2024

Ah awesome, I hadn't seen that! So the next step would be a for a second PR to rename the dependencies and then possibly a third PR to introduce wasm building to the CI process, so that it doesn't get broken going forward?

from swc.

anurbol avatar anurbol commented on May 7, 2024

@alubbe Yep, seems so! Currently I don't have time for this, but this is simple enough so if you have time you could try.

from swc.

alubbe avatar alubbe commented on May 7, 2024

Out of interest, could you include babel or other pure JS alternatives in your benchmark?

from swc.

kdy1 avatar kdy1 commented on May 7, 2024

@alubbe I included babel, but I didn't benchmark tsc because it does much more work than swc. It will be very slow, but it's expected as it does much more work.
For the same reason, I didn't include sucrase because it cannot compile to es3 / es2015.

from swc.

alubbe avatar alubbe commented on May 7, 2024

Ah you're right, it's at the end of the benchmark. So for es2015, the WASM version is around 4-5 times faster and the native one is around 9 times faster than babel, right?

from swc.

kdy1 avatar kdy1 commented on May 7, 2024

@alubbe Oh. I made a mistake. es2015 in swc is equivalent with es5 because there's no es2015 -> es5 pass. I added a description to the pr.

So the native version is 17 times faster than babel.

from swc.

swc-bot avatar swc-bot commented on May 7, 2024

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.

from swc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.