@@ -51,8 +51,9 @@ pub type HostProvider = FillProvider<
51
51
RootProvider ,
52
52
> ;
53
53
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 ;
56
57
57
58
/// Configuration for a builder running a specific rollup on a specific host
58
59
/// chain.
@@ -153,10 +154,9 @@ pub struct BuilderConfig {
153
154
/// The max number of simultaneous block simulations to run.
154
155
#[ from_env(
155
156
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"
158
158
) ]
159
- pub concurrency_limit : usize ,
159
+ pub concurrency_limit : Option < usize > ,
160
160
161
161
/// The slot calculator for the builder.
162
162
pub slot_calculator : SlotCalculator ,
@@ -281,13 +281,21 @@ impl BuilderConfig {
281
281
SignetCfgEnv { chain_id : self . ru_chain_id }
282
282
}
283
283
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.
285
286
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 ( || {
287
296
std:: thread:: available_parallelism ( )
288
297
. map ( |p| p. get ( ) )
289
- . unwrap_or ( DEFAULT_CONCURRENCY_LIMIT ) ;
290
- }
291
- self . concurrency_limit
298
+ . unwrap_or ( DEFAULT_CONCURRENCY_LIMIT )
299
+ } )
292
300
}
293
301
}
0 commit comments