@@ -51,8 +51,9 @@ pub type HostProvider = FillProvider<
5151 RootProvider ,
5252> ;
5353
54- /// The default concurrency limit for the builder if system call fails.
55- pub const DEFAULT_CONCURRENCY_LIMIT : usize = 4 ;
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 ;
5657
5758/// Configuration for a builder running a specific rollup on a specific host
5859/// chain.
@@ -153,10 +154,9 @@ pub struct BuilderConfig {
153154 /// The max number of simultaneous block simulations to run.
154155 #[ from_env(
155156 var = "CONCURRENCY_LIMIT" ,
156- desc = "The max number of simultaneous block simulations to run" ,
157- optional
157+ desc = "The max number of simultaneous block simulations to run"
158158 ) ]
159- pub concurrency_limit : usize ,
159+ pub concurrency_limit : Option < usize > ,
160160
161161 /// The slot calculator for the builder.
162162 pub slot_calculator : SlotCalculator ,
@@ -281,13 +281,21 @@ impl BuilderConfig {
281281 SignetCfgEnv { chain_id : self . ru_chain_id }
282282 }
283283
284- /// Get the concurrency limit for the current system.
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.
285286 pub fn concurrency_limit ( & self ) -> usize {
286- if self . concurrency_limit == 0 {
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 ( || {
287296 std:: thread:: available_parallelism ( )
288297 . map ( |p| p. get ( ) )
289- . unwrap_or ( DEFAULT_CONCURRENCY_LIMIT ) ;
290- }
291- self . concurrency_limit
298+ . unwrap_or ( DEFAULT_CONCURRENCY_LIMIT )
299+ } )
292300 }
293301}
0 commit comments