* Pool size from CPU headroom, memory headroom, and the explicit override. * Pure — every input injected — so the whole matrix is unit-testable. * * CPU term: `availableParallelism` (cpuset/affinity-honest — `os.cpus()` * enumerates the host's CPUs and sized SIX workers inside a 2-CPU cp
(opts: {
explicit?: string;
availableParallelism: number;
memoryBudget: number;
dbSizeBytes: number;
/** The workers the work is worth; left out, as many as the machine can carry. */
worth?: number;
})
| 191 | * cost — callers get null and stay sequential. |
| 192 | */ |
| 193 | static resolvePoolSize(opts: { |
| 194 | explicit?: string; |
| 195 | availableParallelism: number; |
| 196 | memoryBudget: number; |
| 197 | dbSizeBytes: number; |
| 198 | /** The workers the work is worth; left out, as many as the machine can carry. */ |
| 199 | worth?: number; |
| 200 | }): number | null { |
| 201 | if (opts.explicit !== undefined && opts.explicit !== '') { |
| 202 | const n = Number.parseInt(opts.explicit, 10); |
| 203 | if (Number.isFinite(n)) { |
| 204 | if (n <= 0) return null; |
| 205 | return Math.min(n, 16); |
| 206 | } |
| 207 | } |
| 208 | // No floor: at ap=2 the pool LOSES to sequential outright — measured on |
| 209 | // the kernel-scale 2-cpuset envelope: resolution 853s sequential vs |
| 210 | // 1,150s pooled-6-on-2 (§7a.1), and synthesis is Amdahl-bound by its |
| 211 | // dominant pass (cFnPtrEdges 306s of 358s) so pooling it bought nothing. |
| 212 | // ap−1 < 2 ⇒ sequential is the fast path, not a fallback. |
| 213 | const cpuCap = Math.min(opts.availableParallelism - 1, MAX_RESOLVE_WORKERS); |
| 214 | const perWorker = Math.min(Math.max(opts.dbSizeBytes * 0.2, 256 * 1024 * 1024), 1.5 * 1024 * 1024 * 1024); |
| 215 | const memCap = Math.floor((opts.memoryBudget * 0.7) / perWorker); |
| 216 | const size = Math.min(cpuCap, memCap); |
| 217 | return size >= 2 ? Math.min(size, Math.max(2, opts.worth ?? size)) : null; |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * Create a pool when the compiled worker exists (absent when running from |