Skip to content

Commit 6124e73

Browse files
authored
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 ec44a24 commit 6124e73

File tree

18 files changed

+456
-442
lines changed

18 files changed

+456
-442
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
@@ -299,21 +299,25 @@ turbopack-trace-utils = { path = "turbopack/crates/turbopack-trace-utils" }
299299
turbopack-wasm = { path = "turbopack/crates/turbopack-wasm" }
300300

301301
# SWC crates
302-
swc_core = { version = "30.1.1", features = [
302+
swc_core = { version = "34", features = [
303303
"ecma_loader_lru",
304304
"ecma_loader_parking_lot",
305305
"parallel_rayon",
306306
] }
307-
testing = { version = "14.0.0" }
307+
testing = "15.0.0"
308308

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

318322
# General Deps
319323
chromiumoxide = { version = "0.5.4", features = [
@@ -439,6 +443,6 @@ webbrowser = "0.8.7"
439443

440444
[patch.crates-io]
441445
hyper = { git = "https://github.com/bgw/hyper-rs.git", branch = "v1.6.0-with-macos-intel-miscompilation-workaround" }
446+
mdxjs = { git = "https://github.com/mischnic/mdxjs-rs.git", branch = "swc-core-32" }
442447
lightningcss = { git = "https://github.com/parcel-bundler/lightningcss.git", branch = "mischnic/bump-browserslist" }
443-
mdxjs = { git = "https://github.com/kdy1/mdxjs-rs.git", branch = "swc-core-30" }
444448
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
@@ -82,6 +82,7 @@ swc_core = { workspace = true, features = [
8282
"ecma_ast",
8383
"ecma_ast_serde",
8484
"ecma_codegen",
85+
"ecma_helpers_inline",
8586
"ecma_loader_lru",
8687
"ecma_loader_node",
8788
"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"] }

packages/next/src/build/swc/generated-native.d.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,19 @@ export interface NapiWatchOptions {
100100
}
101101
export interface NapiProjectOptions {
102102
/**
103-
* An absolute root path from which all files must be nested under. Trying to access
104-
* a file outside this root will fail, so think of this as a chroot.
103+
* An absolute root path (Unix or Windows path) from which all files must be nested under.
104+
* Trying to access a file outside this root will fail, so think of this as a chroot.
105105
* E.g. `/home/user/projects/my-repo`.
106106
*/
107107
rootPath: RcStr
108108
/**
109-
* A path which contains the app/pages directories, relative to [`Project::root_path`].
110-
* E.g. `apps/my-app`
109+
* A path which contains the app/pages directories, relative to [`Project::root_path`], always
110+
* Unix path. E.g. `apps/my-app`
111111
*/
112112
projectPath: RcStr
113113
/**
114-
* A path where to emit the build outputs, relative to [`Project::project_path`].
115-
* Corresponds to next.config.js's `distDir`.
114+
* A path where to emit the build outputs, relative to [`Project::project_path`], always Unix
115+
* path. Corresponds to next.config.js's `distDir`.
116116
* E.g. `.next`
117117
*/
118118
distDir: RcStr
@@ -151,19 +151,20 @@ export interface NapiProjectOptions {
151151
/** [NapiProjectOptions] with all fields optional. */
152152
export interface NapiPartialProjectOptions {
153153
/**
154-
* An absolute root path from which all files must be nested under. Trying to access
155-
* a file outside this root will fail, so think of this as a chroot.
154+
* An absolute root path (Unix or Windows path) from which all files must be nested under.
155+
* Trying to access a file outside this root will fail, so think of this as a chroot.
156156
* E.g. `/home/user/projects/my-repo`.
157157
*/
158158
rootPath?: RcStr
159159
/**
160-
* A path which contains the app/pages directories, relative to [`Project::root_path`].
160+
* A path which contains the app/pages directories, relative to [`Project::root_path`], always
161+
* a Unix path.
161162
* E.g. `apps/my-app`
162163
*/
163164
projectPath?: RcStr
164165
/**
165-
* A path where to emit the build outputs, relative to [`Project::project_path`].
166-
* Corresponds to next.config.js's `distDir`.
166+
* A path where to emit the build outputs, relative to [`Project::project_path`], always a
167+
* Unix path. Corresponds to next.config.js's `distDir`.
167168
* E.g. `.next`
168169
*/
169170
distDir?: RcStr | undefined | null

0 commit comments

Comments
 (0)