Comments (18)
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.
@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.
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.
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.
#691 Is merged. Closing. Please comment or file a new issue if it's not enough.
from swc.
You may want to check out #87
from swc.
@kdy1 Continuing #87 (comment)... So what are those cfg
s 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.
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.
@anurbol I'll be happy with a such PR. Thank you for the interest on swc!
from swc.
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.
@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.
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.
@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.
Out of interest, could you include babel or other pure JS alternatives in your benchmark?
from swc.
@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.
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.
@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.
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)
- Fail to parse import attributes in TSTypeAlias
- `NestJS` application initialised twice with `SWC` HOT 2
- add `/*#__PURE__*/` for ts enum HOT 2
- SWC generate invalid source map when inputSourceMap is provided HOT 7
- Unexpected crash when compiling a TypeScript class with a private readonly constructor parameter and JSX within the constructor.
- The strip-type-only mode does not handle export overloads functions
- Provide AST count information without a separate visitor pass HOT 2
- Add LICENSE to @swc/wasm-typescript HOT 2
- HTML is modified through swc_html-visit and the generated HTML string from swc_html-codegen is used to convert " to " HOT 1
- HTML is modified through swc_html-visit and the generated HTML string from swc_html-codegen is used to convert " to " HOT 4
- @swc/wasm-typescript transform mode should no perform import elision HOT 3
- failed to read input source map - @swc/jest + yarn PnP workspaces HOT 6
- Can SWC match TS emit for Parameter Properties? HOT 5
- Make CDN ESM paths work HOT 3
- Error compiling ` Compiling swc v0.280.0` when installing the `swc_cli` package. HOT 1
- `cargo install swc_cli` issue referencing not stable api HOT 1
- `dead_branch_remover` incorrectly removes `init` part of `VariableDeclarator` node HOT 4
- Cannot implement decorator as a private method
- reflect-metadata does not work as expected in some scenarios HOT 7
- swc.transform: decorators - descriptor is undefined HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swc.