-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
swc as a javascript parser #13425
Comments
@kdy1 Let's start, does Because I think we can add hook(s) on parser stage so you can change |
Parsing in javascript is slow, and blocks the js thread for a while, so I want to see if it's possible to offload parsing to nodejs thread pool using swc. I think double parsing with swc is not a big problem, as it the not block js thread. But I'm not sure if it's
If this is possible, it would make the job much easier |
Should be yes (due https://github.com/estree/estree#estree-steering-committee, but need check), but here other problem webpack understand only stage 4, so if you return new/unknown AST node the result will be unpredictable.
Can you describe it deeply? Do you want handle js parsring/code generation in multi threading? Maybe you can provide place where you need inject cwd? |
swc supports stage 3 and swc has compatibility transforms so it would not be a problem.
What I want to do is reducing time used by the parser. And by
I mean parsing twice would not affect performance greatly. |
But why do not use loader in this case? I'm a little confused, maybe you can show it using pseudo code on |
Oh, you are right. |
This issue had no activity for at least three months. It's subject to automatic issue closing if there is no activity in the next 15 days. |
Issue was closed because of inactivity. If you think this is still a valid issue, please file a new issue with additional information. |
@kdy1 still valid? |
@alexander-akait Of course, I'd be happy to make it faster. |
For at least initial/demonstration purposes, I think tacking on to swc-loader makes sense here (otherwise, we would have to make a bunch of changes to asyncify the parser parsing - not impossible, but isnt necessarily blocking). Assuming ast's are compatible (which small test indicates they arent, but they may be close) The simplest way to get this working using swc-loader, IMO:
The main incompatible property set that stands out right now, though, is start/end/loc/range properties. I dont see an option to get the exact Additionally, webpack expects comment blocks to be parsed and available in the AST, which seems to also be missing from swc edit:i also have done some reading on the issues related to sending back ASTs and see the perf hits, so thats definitely also something to be considered, because the whole JavascriptParser class probabably cant be moved to native due to all the hooks usage |
Yeah actually I made rust module that can generate acorn AST from source code. I'll check how it performs using swc-loader first. Of course, it has start/end/loc/comments/etc.. |
@mohsen1 The swc codebase has rust code to create babel/acorn ast and of course those have comments stored in the struct. I'll add a way to get webpack ast from node js. Filed swc-project/swc#3437 |
I have one question. Should I add the API to
|
@kdy1 About comments, does it supported or not? I’m confused a bit 🤔 (swc-project/swc#2964 (comment)) |
@coderaiser You can don't worry, because if decide to do it (and most likely it will), it will be experiment, so you can report about any problems in swc |
It's supported and rust type definitions for acorn/babel AST store comments inline. |
@alexander-akait I also waiting for ability to use rust-based solution to produce I’m working on linter 🐊 So, thank you, but I cannot not worry :), since it’s related to software I’m working on. @kdy1 Here is one of the ways how API can look like: const {parseSync} = require('@swc/core');
const ast = parseSync(`const hello = 'world'`, {
type: ‘estree | babel | swc (default)’
}); No need to use any experimental flags, such API is obvious and straight forward, and of course any bug will be reported to swc repo :). Worry not about bundle size, if it will be less then one that TypeScript has it will be already amazing 😏. But practical usage is more useful then very long term planning. |
@coderaiser Yep, it is not hard task, we need add new options to allow setup parser in webpack (and mark it as experimental so we can do breaking changes between versions) and add cross tests to check all our tests (I think we can catch some problems on early stage). For for your interest we are working on rust based linter solution https://github.com/swc-project/swc/tree/main/crates/swc_ecma_lints, so if you want to be more faster and safely you can help ⭐ |
I am interested. I’m not as good in rust as in JavaScript 😅, but I have two questions: 🤷 Why so much code for such simple task, as warning about
|
Just a little question about swc: If I use swc-loader as a babel-loader replacement, what are the trade-offs excluding the compilation speed? |
Feature request
Follow up of #13408 (reply in thread)
I'm author of the swc project and I'm looking for way to improve the performance of webpack.
Parsing something in javascript is a very expensive task, so I think using the parser of swc with libuv worker thread will improve performance a lot. (Also, it does not block js thread, so other codes can run while parsing.)
But currently, webpack does not allow overriding dependency analysis and it seems like I have to reimplement the whole
JavascriptPlugin
. If there's an easier way to improve performance, it would be great.I'll create a standalone parser package if required.
What is the expected behavior?
Returning dependency graph from a loader.
What is motivation or use case for adding/changing the behavior?
Huge performance improvements.
How should this be implemented in your opinion?
By returning graph object or list from a loader.
Are you willing to work on this yourself?
Yes.
The text was updated successfully, but these errors were encountered: