@@ -51,6 +51,10 @@ pub type HostProvider = FillProvider<
5151 RootProvider ,
5252> ;
5353
54+ /// The default concurrency limit for the builder if the system call
55+ /// fails and no user-specified value is set.
56+ pub const DEFAULT_CONCURRENCY_LIMIT : usize = 8 ;
57+
5458/// Configuration for a builder running a specific rollup on a specific host
5559/// chain.
5660#[ derive( Debug , Clone , FromEnv ) ]
@@ -152,7 +156,7 @@ pub struct BuilderConfig {
152156 var = "CONCURRENCY_LIMIT" ,
153157 desc = "The max number of simultaneous block simulations to run"
154158 ) ]
155- pub concurrency_limit : usize ,
159+ pub concurrency_limit : Option < usize > ,
156160
157161 /// The slot calculator for the builder.
158162 pub slot_calculator : SlotCalculator ,
@@ -276,4 +280,22 @@ impl BuilderConfig {
276280 pub const fn cfg_env ( & self ) -> SignetCfgEnv {
277281 SignetCfgEnv { chain_id : self . ru_chain_id }
278282 }
283+
284+ /// Memoizes the concurrency limit for the current system. Uses [`std::thread::available_parallelism`] if no
285+ /// value is set. If that for some reason fails, it returns the default concurrency limit.
286+ pub fn concurrency_limit ( & self ) -> usize {
287+ static ONCE : std:: sync:: OnceLock < usize > = std:: sync:: OnceLock :: new ( ) ;
288+
289+ if let Some ( limit) = self . concurrency_limit {
290+ if limit > 0 {
291+ return limit;
292+ }
293+ }
294+
295+ * ONCE . get_or_init ( || {
296+ std:: thread:: available_parallelism ( )
297+ . map ( |p| p. get ( ) )
298+ . unwrap_or ( DEFAULT_CONCURRENCY_LIMIT )
299+ } )
300+ }
279301}
0 commit comments