Skip to content

Commit 6d0ffcc

Browse files
mischniclukesandberg
authored andcommitted
Upgrade to swc v33 (#81750)
So what do we need to do about swc-project/swc#10813? Not sure when we'd call `global_atom_store_gc()` https://vercel.slack.com/archives/C03EWR7LGEN/p1752228740427529 The 2s-debounced gc calls didn't have a measurable effect on `next build --turbo`: ``` with gc: 360.90s user 80.74s system 688% cpu 1:04.15 total 357.24s user 82.61s system 664% cpu 1:06.23 total without gc: 360.51s user 80.48s system 698% cpu 1:03.16 total 355.21s user 79.99s system 667% cpu 1:05.18 total ``` - [x] ~~Blocked on swc-project/swc#10878 - [ ] swc-project/swc#10930 Closes #81898
1 parent e545417 commit 6d0ffcc

File tree

17 files changed

+444
-431
lines changed

17 files changed

+444
-431
lines changed

Cargo.lock

Lines changed: 331 additions & 386 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -298,21 +298,25 @@ turbopack-trace-utils = { path = "turbopack/crates/turbopack-trace-utils" }
298298
turbopack-wasm = { path = "turbopack/crates/turbopack-wasm" }
299299

300300
# SWC crates
301-
swc_core = { version = "30.1.1", features = [
301+
swc_core = { version = "34", features = [
302302
"ecma_loader_lru",
303303
"ecma_loader_parking_lot",
304304
"parallel_rayon",
305305
] }
306-
testing = { version = "14.0.0" }
306+
testing = "15.0.0"
307307

308308
# Keep consistent with preset_env_base through swc_core
309-
browserslist-rs = { version = "0.19.0" }
309+
browserslist-rs = "0.19.0"
310310
mdxjs = "1.0.3"
311-
modularize_imports = { version = "0.90.0" }
312-
styled_components = { version = "0.118.0" }
313-
styled_jsx = { version = "0.94.0" }
314-
swc_emotion = { version = "0.94.0" }
315-
swc_relay = { version = "0.64.0" }
311+
modularize_imports = "0.93.0"
312+
styled_components = "0.121.0"
313+
styled_jsx = "0.97.0"
314+
swc_emotion = "0.97.0"
315+
swc_relay = "0.67.0"
316+
react_remove_properties = "0.47.0"
317+
remove_console = "0.48.0"
318+
preset_env_base = "5.0.0"
319+
316320

317321
# General Deps
318322
chromiumoxide = { version = "0.5.4", features = [
@@ -435,6 +439,6 @@ webbrowser = "0.8.7"
435439

436440
[patch.crates-io]
437441
hyper = { git = "https://github.com/bgw/hyper-rs.git", branch = "v1.6.0-with-macos-intel-miscompilation-workaround" }
442+
mdxjs = { git = "https://github.com/mischnic/mdxjs-rs.git", branch = "swc-core-32" }
438443
lightningcss = { git = "https://github.com/parcel-bundler/lightningcss.git", branch = "mischnic/bump-browserslist" }
439-
mdxjs = { git = "https://github.com/kdy1/mdxjs-rs.git", branch = "swc-core-30" }
440444
parcel_selectors = { git = "https://github.com/parcel-bundler/lightningcss.git", branch = "mischnic/bump-browserslist" }

crates/napi/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ swc_core = { workspace = true, features = [
8181
"ecma_ast",
8282
"ecma_ast_serde",
8383
"ecma_codegen",
84+
"ecma_helpers_inline",
8485
"ecma_loader_lru",
8586
"ecma_loader_node",
8687
"ecma_minifier",

crates/napi/src/lib.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,15 @@ static ALLOC: dhat::Alloc = dhat::Alloc;
7070
#[cfg(not(target_arch = "wasm32"))]
7171
#[napi::module_init]
7272
fn init() {
73-
use std::panic::{set_hook, take_hook};
73+
use std::{
74+
cell::RefCell,
75+
panic::{set_hook, take_hook},
76+
time::{Duration, Instant},
77+
};
78+
79+
thread_local! {
80+
static LAST_SWC_ATOM_GC_TIME: RefCell<Option<Instant>> = const { RefCell::new(None) };
81+
}
7482

7583
use tokio::runtime::Builder;
7684
use turbo_tasks::panic_hooks::handle_panic;
@@ -87,6 +95,14 @@ fn init() {
8795
.on_thread_stop(|| {
8896
TurboMalloc::thread_stop();
8997
})
98+
.on_thread_park(|| {
99+
LAST_SWC_ATOM_GC_TIME.with_borrow_mut(|cell| {
100+
if cell.is_none_or(|t| t.elapsed() > Duration::from_secs(2)) {
101+
swc_core::ecma::atoms::hstr::global_atom_store_gc();
102+
*cell = Some(Instant::now());
103+
}
104+
});
105+
})
90106
.disable_lifo_slot()
91107
.build()
92108
.unwrap();

crates/next-api/benches/hmr.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::{
2+
cell::RefCell,
23
fs::{create_dir_all, write},
34
mem::forget,
45
path::{Path, PathBuf},
@@ -154,11 +155,23 @@ fn load_next_config() -> RcStr {
154155
}
155156

156157
fn runtime() -> Runtime {
158+
thread_local! {
159+
static LAST_SWC_ATOM_GC_TIME: RefCell<Option<Instant>> = const { RefCell::new(None) };
160+
}
161+
157162
tokio::runtime::Builder::new_multi_thread()
158163
.enable_all()
159164
.on_thread_stop(|| {
160165
turbo_tasks_malloc::TurboMalloc::thread_stop();
161166
})
167+
.on_thread_park(|| {
168+
LAST_SWC_ATOM_GC_TIME.with_borrow_mut(|cell| {
169+
if cell.is_none_or(|t| t.elapsed() > Duration::from_secs(2)) {
170+
swc_core::ecma::atoms::hstr::global_atom_store_gc();
171+
*cell = Some(Instant::now());
172+
}
173+
});
174+
})
162175
.build()
163176
.context("Failed to build tokio runtime")
164177
.unwrap()

crates/next-build-test/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ next-api = { workspace = true }
1616
next-core = { workspace = true }
1717
num_cpus = "1.16.0"
1818
rand = { workspace = true, features = ["small_rng"] }
19+
swc_core = { workspace = true }
1920
serde_json = { workspace = true }
2021
tokio = { workspace = true, features = ["full"] }
2122
tokio-stream = "0.1.15"

crates/next-build-test/src/main.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
use std::{convert::Infallible, str::FromStr, time::Instant};
1+
use std::{
2+
cell::RefCell,
3+
convert::Infallible,
4+
str::FromStr,
5+
time::{Duration, Instant},
6+
};
27

38
use next_api::project::{DefineEnv, ProjectOptions};
49
use next_build_test::{Strategy, main_inner};
@@ -70,12 +75,23 @@ fn main() {
7075
factor = 1;
7176
}
7277

78+
thread_local! {
79+
static LAST_SWC_ATOM_GC_TIME: RefCell<Option<Instant>> = const { RefCell::new(None) };
80+
}
7381
tokio::runtime::Builder::new_multi_thread()
7482
.enable_all()
7583
.on_thread_stop(|| {
7684
TurboMalloc::thread_stop();
7785
tracing::debug!("threads stopped");
7886
})
87+
.on_thread_park(|| {
88+
LAST_SWC_ATOM_GC_TIME.with_borrow_mut(|cell| {
89+
if cell.is_none_or(|t| t.elapsed() > Duration::from_secs(2)) {
90+
swc_core::ecma::atoms::hstr::global_atom_store_gc();
91+
*cell = Some(Instant::now());
92+
}
93+
});
94+
})
7995
.build()
8096
.unwrap()
8197
.block_on(async {

crates/next-core/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ futures = { workspace = true }
3131
thiserror = { workspace = true }
3232
tracing = { workspace = true }
3333
rustc-hash = { workspace = true }
34-
react_remove_properties = "0.44.0"
35-
remove_console = "0.45.0"
34+
react_remove_properties = { workspace = true }
35+
remove_console = { workspace = true }
3636
itertools = { workspace = true }
3737
percent-encoding = "2.3.1"
3838
serde_path_to_error = { workspace = true }

crates/next-custom-transforms/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ turbopack-ecmascript-plugins = { workspace = true, optional = true }
6767
turbo-rcstr = { workspace = true }
6868
urlencoding = { workspace = true }
6969

70-
react_remove_properties = "0.44.0"
71-
remove_console = "0.45.0"
72-
preset_env_base = "4.0.0"
70+
react_remove_properties = { workspace = true }
71+
remove_console = { workspace = true }
72+
preset_env_base = { workspace = true }
7373

7474
[dev-dependencies]
7575
swc_core = { workspace = true, features = ["testing_transform"] }

test/development/acceptance-app/error-recovery.test.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ describe('Error recovery app', () => {
142142
"description": "Parsing ecmascript source code failed",
143143
"environmentLabel": null,
144144
"label": "Build Error",
145-
"source": "./app/server/page.js (2:27)
145+
"source": "./app/server/page.js (2:26)
146146
Parsing ecmascript source code failed
147147
> 2 | return <p>Hello world</p>
148-
| ^",
148+
| ^",
149149
"stack": [],
150150
}
151151
`)
@@ -160,7 +160,7 @@ describe('Error recovery app', () => {
160160
,-[2:1]
161161
1 | export default function Page() {
162162
2 | return <p>Hello world</p>
163-
: ^
163+
: ^
164164
\`----
165165
Caused by:
166166
Syntax Error
@@ -206,10 +206,10 @@ describe('Error recovery app', () => {
206206
"description": "Parsing ecmascript source code failed",
207207
"environmentLabel": null,
208208
"label": "Build Error",
209-
"source": "./app/client/page.js (2:27)
209+
"source": "./app/client/page.js (2:26)
210210
Parsing ecmascript source code failed
211211
> 2 | return <p>Hello world</p>
212-
| ^",
212+
| ^",
213213
"stack": [],
214214
}
215215
`)
@@ -224,7 +224,7 @@ describe('Error recovery app', () => {
224224
,-[2:1]
225225
1 | export default function Page() {
226226
2 | return <p>Hello world</p>
227-
: ^
227+
: ^
228228
\`----
229229
Caused by:
230230
Syntax Error
@@ -619,10 +619,10 @@ describe('Error recovery app', () => {
619619
"description": "Parsing ecmascript source code failed",
620620
"environmentLabel": null,
621621
"label": "Build Error",
622-
"source": "./index.js (10:41)
622+
"source": "./index.js (10:39)
623623
Parsing ecmascript source code failed
624624
> 10 | export default function FunctionNamed() {
625-
| ^",
625+
| ^",
626626
"stack": [],
627627
}
628628
`)
@@ -636,7 +636,7 @@ describe('Error recovery app', () => {
636636
Error: x Expected '}', got '<eof>'
637637
,-[10:1]
638638
10 | export default function FunctionNamed() {
639-
: ^
639+
: ^
640640
\`----
641641
Caused by:
642642
Syntax Error
@@ -656,10 +656,10 @@ describe('Error recovery app', () => {
656656
"description": "Parsing ecmascript source code failed",
657657
"environmentLabel": null,
658658
"label": "Build Error",
659-
"source": "./index.js (10:41)
659+
"source": "./index.js (10:39)
660660
Parsing ecmascript source code failed
661661
> 10 | export default function FunctionNamed() {
662-
| ^",
662+
| ^",
663663
"stack": [],
664664
}
665665
`)
@@ -673,7 +673,7 @@ describe('Error recovery app', () => {
673673
Error: x Expected '}', got '<eof>'
674674
,-[10:1]
675675
10 | export default function FunctionNamed() {
676-
: ^
676+
: ^
677677
\`----
678678
Caused by:
679679
Syntax Error
@@ -1012,10 +1012,10 @@ describe('Error recovery app', () => {
10121012
"description": "Parsing ecmascript source code failed",
10131013
"environmentLabel": null,
10141014
"label": "Build Error",
1015-
"source": "./app/page.js (1:3)
1015+
"source": "./app/page.js (1:2)
10161016
Parsing ecmascript source code failed
10171017
> 1 | {{{
1018-
| ^",
1018+
| ^",
10191019
"stack": [],
10201020
}
10211021
`)
@@ -1029,7 +1029,7 @@ describe('Error recovery app', () => {
10291029
Error: x Expected '}', got '<eof>'
10301030
,----
10311031
1 | {{{
1032-
: ^
1032+
: ^
10331033
\`----
10341034
Caused by:
10351035
Syntax Error",

0 commit comments

Comments
 (0)