File tree Expand file tree Collapse file tree 7 files changed +70
-7
lines changed
turbopack/crates/turbopack-cli Expand file tree Collapse file tree 7 files changed +70
-7
lines changed Original file line number Diff line number Diff line change @@ -70,7 +70,15 @@ static ALLOC: dhat::Alloc = dhat::Alloc;
7070#[ cfg( not( target_arch = "wasm32" ) ) ]
7171#[ napi:: module_init]
7272fn 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 ( ) ;
Original file line number Diff line number Diff line change 11use 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
156157fn 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 ( )
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ next-api = { workspace = true }
1616next-core = { workspace = true }
1717num_cpus = " 1.16.0"
1818rand = { workspace = true , features = [" small_rng" ] }
19+ swc_core = { workspace = true }
1920serde_json = { workspace = true }
2021tokio = { workspace = true , features = [" full" ] }
2122tokio-stream = " 0.1.15"
Original file line number Diff line number Diff line change 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
38use next_api:: project:: { DefineEnv , ProjectOptions } ;
49use 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 {
Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ futures = { workspace = true }
4545owo-colors = { workspace = true }
4646rustc-hash = { workspace = true }
4747serde = { workspace = true }
48+ swc_core = { workspace = true }
4849tokio = { workspace = true , features = [" full" ] }
4950tracing = { workspace = true }
5051tracing-subscriber = { workspace = true , features = [" json" ] }
Original file line number Diff line number Diff line change 11#![ feature( future_join) ]
22#![ feature( min_specialization) ]
33
4- use std:: path:: Path ;
4+ use std:: { cell :: RefCell , path:: Path , time :: Instant } ;
55
66use anyhow:: { Context , Result } ;
77use clap:: Parser ;
@@ -22,16 +22,30 @@ use turbopack_trace_utils::{
2222static ALLOC : TurboMalloc = TurboMalloc ;
2323
2424fn main ( ) {
25- let args = Arguments :: parse ( ) ;
25+ thread_local ! {
26+ static LAST_SWC_ATOM_GC_TIME : RefCell <Option <Instant >> = const { RefCell :: new( None ) } ;
27+ }
2628
2729 let mut rt = tokio:: runtime:: Builder :: new_multi_thread ( ) ;
28- rt. enable_all ( ) . on_thread_stop ( || {
29- TurboMalloc :: thread_stop ( ) ;
30- } ) ;
30+ rt. enable_all ( )
31+ . on_thread_stop ( || {
32+ TurboMalloc :: thread_stop ( ) ;
33+ } )
34+ . on_thread_park ( || {
35+ LAST_SWC_ATOM_GC_TIME . with_borrow_mut ( |cell| {
36+ use std:: time:: Duration ;
37+
38+ if cell. is_none_or ( |t| t. elapsed ( ) > Duration :: from_secs ( 2 ) ) {
39+ swc_core:: ecma:: atoms:: hstr:: global_atom_store_gc ( ) ;
40+ * cell = Some ( Instant :: now ( ) ) ;
41+ }
42+ } ) ;
43+ } ) ;
3144
3245 #[ cfg( not( codspeed) ) ]
3346 rt. disable_lifo_slot ( ) ;
3447
48+ let args = Arguments :: parse ( ) ;
3549 rt. build ( ) . unwrap ( ) . block_on ( main_inner ( args) ) . unwrap ( ) ;
3650}
3751
You can’t perform that action at this time.
0 commit comments