1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//! Shared logic for sizing CPU parallelism from the `RERUN_SDK_NUM_CPUS` environment variable.
use LazyLock;
/// The machine's available parallelism, or `2` if it can't be determined.
///
/// The fallback is `2` rather than `1` so a pool sized from this keeps some concurrency
/// even on the rare platform where the core count can't be detected.
///
/// Computed once and cached for the lifetime of the process.
/// The value of the `RERUN_SDK_NUM_CPUS` environment variable, clamped to `[1, available_cpus()]`.
///
/// Returns `None` if the variable is unset, leaving the caller free to pick its own default.
/// If the variable is set but unparsable, this `warn_once!`s and returns `None`, so a typo
/// degrades to the default rather than silently pinning some surprising value.
///
/// A fractional value is truncated; clamping to `[1, available_cpus()]` guards against
/// infinity / huge values and ensures we never exceed the machine's actual core count.
///
/// Read once and cached for the lifetime of the process (so changing the variable at
/// runtime has no effect).