-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Make swc compile faster. #7071
Comments
swc_ecma_minifier
compile faster.
I wonder if this works: https://github.com/dtolnay/watt |
Are you using codegen-units=1? |
Ah yeah you are using it. I think that's the main problem |
I know. I'm talking about codegen times of transform/minifier crates. |
I wonder if the macro implementations are sub-optimal, for example https://users.rust-lang.org/t/5-hours-to-compile-macro-what-can-i-do/36508 |
Yeah, they are not optimal. It's a known issue |
Assign this to me if you don't have the time, I'll dig deeper. |
This is not a focus, at least at the moment. I have time, but I don't want to use my personal time for this. You can create fake types like Currently |
Summoned via https://twitter.com/boshen_c/status/1635842195113787392, I took a look at this. First, I'll consider the high codegen times for some of the crates. I have an Intel i9-7940X which has 14 physical cores and 28 virtual cores. My compile times for
So, a pretty small jump going from
And here is the same part for an opt build: Note that the purple (codegen) part is massively bigger in the release build. I've never seen so much purple in a
I then tried profiling the compiler with and for an opt build:
For the debug build we have four "opt" threads, which are I don't know much about these "LTO" threads, and why one of them would be so slow. It definitely seems odd. The crate has only 767 lines of Rust code in it, and it looks like very normal, reasonable code. My current theory is that one of the crates that Ok, there ends part 1 of my analysis. |
@nnethercote Thank you so much for looking into this.
The rspack project depends on almost all of swc.
I thought it's normal for codegen to take this much time, apparently it's not 😞 So now we have two problems at hand: macros and codegen. |
Oh... I know the solution for the proc macro part, and AFAIK the long codegen is caused by visitors. |
Now for the crates using macros.
I looked at I think it will take project-specific understanding to improve things. Looking at the output of |
That's right. If you look at the earlier |
About macros:
Macros create an enormous amount of code, and I think they can be reduced a bit, but not by a margin. My main trick for reducing the amount of code will be extracting common code to It includes
The proc-macro generates two kinds of visitors. The first one is general visitors used by swc itself, and the second one is a-path-aware visitors used by rspack and turbopack. Btw, can |
I'll work on this |
Parcel (and probably also rspack) currently doesn't use serde/rykv for swc ASTs, so maybe compile time could be improved here by putting that behind a cargo feature. |
I'm working on with #7138
2023년 3월 24일 (금) 오후 7:24, Niklas Mischkulnig ***@***.***>님이
작성:
… cargo expand's output is 120,008 lines of code. That's even more! Much of
that is serializing/deserializing code generated by serde, which is known
to produce verbose code.
Parcel (and probably also rspack) never uses serde/rykv for swc ASTs, so
maybe compile time could be improved here by putting that behind a cargo
feature.
—
Reply to this email directly, view it on GitHub
<#7071 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHELSJ7IQM3ERMHAZIHPQ6LW5VY6DANCNFSM6AAAAAAVYSUUEY>
.
You are receiving this because you were assigned.Message ID:
***@***.***>
|
Can you try |
Rspack is currently stuck on an older version due to #7085, I'll report back the improvements once we upgrade to the latest version when that's fixed on our end. |
Not sure if I did something wrong, but the compiletime didn't get better for Parcel on my machine:
I ran |
Oh... interesting.
This was the result for turbopack, but this is before AST change |
I found cargo-llvm-lines from matklad's blog post. This can be used to guide your refactoring, e.g.
In some other place:
In cases where generics can not be removed, https://matklad.github.io/2021/09/04/fast-rust-builds.html#Keeping-Instantiations-In-Check explains the "inner" technique. |
This comment was marked as spam.
This comment was marked as spam.
I'll tackle this again in the near future. I want to make ES AST/parser extensible and have related idea, but it will make compilation slower |
I think one of the biggest problems is the lack of parallelism, and wrote #7911 It's RFC, and I want to hear opinions about such CLI tool. |
#8110 should improve compile time a bit. Also, this is an experiment for turbopack, but depending directly on crates makes compilation faster. vercel/turborepo#5879 I'm going to create a CLI tool to manage just as you were using |
I marked it as spam because of this part. |
I ran Before: 4m 40s Timings reports: cargo-timings.zip |
**Description:** **Related issue:** - Closes #7071.
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. |
Describe the feature
Some of the crates compile ridiculously slow. It would be really nice if we can speed it up a bit.
From
cargo build --release --timings
:Additional context
Cross link: web-infra-dev/rspack#2202
Update:
swc_ecma_visit
andswc_css_visit
is blocking compilation for a whole minute due to heavy usage of macros. See https://github.com/swc-project/swc/blob/main/crates/swc_ecma_visit/src/lib.rsThe text was updated successfully, but these errors were encountered: