* Create a pool when the compiled worker exists (absent when running from * source in tests → callers use the sequential path), the kill switch is * off, and the machine has the cores AND memory to carry it. Returns null * otherwise. `CODEGRAPH_RESOLVE_WORKERS` overrides the computed size
(dbPath: string, projectRoot: string, frameworks?: readonly string[], worth?: number)
| 196 | * (0 disables the pool; values are capped at 16). |
| 197 | */ |
| 198 | static tryCreate(dbPath: string, projectRoot: string, frameworks?: readonly string[], worth?: number): ResolverPool | null { |
| 199 | if (process.env.CODEGRAPH_NO_PARALLEL_RESOLVE === '1') return null; |
| 200 | const workerScript = path.join(__dirname, 'resolver-worker.js'); |
| 201 | if (!fs.existsSync(workerScript)) return null; |
| 202 | let dbSizeBytes = 0; |
| 203 | try { |
| 204 | dbSizeBytes = fs.statSync(dbPath).size; |
| 205 | } catch { /* fresh/missing file — the 256MB per-worker floor applies */ } |
| 206 | const ap = os.availableParallelism(); |
| 207 | const budget = memoryBudgetBytes(); |
| 208 | const size = ResolverPool.resolvePoolSize({ |
| 209 | explicit: process.env.CODEGRAPH_RESOLVE_WORKERS, |
| 210 | availableParallelism: ap, |
| 211 | memoryBudget: budget, |
| 212 | dbSizeBytes, |
| 213 | worth, |
| 214 | }); |
| 215 | // Both outcomes log under SYNTH_TIMINGS — a silent null is how §7a.1's |
| 216 | // diagnostic run hid the memory-term misfire for a whole 25-minute cycle. |
| 217 | if (process.env.CODEGRAPH_SYNTH_TIMINGS) { |
| 218 | console.error( |
| 219 | `[pool-timing] pool ${size === null ? 'disabled' : `size=${size}`} (ap=${ap} budget=${Math.round(budget / 1024 / 1024)}MB db=${Math.round(dbSizeBytes / 1024 / 1024)}MB)` |
| 220 | ); |
| 221 | } |
| 222 | if (size === null) return null; |
| 223 | try { |
| 224 | return new ResolverPool(workerScript, dbPath, projectRoot, size, frameworks); |
| 225 | } catch { |
| 226 | return null; |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | private constructor(workerScript: string, dbPath: string, projectRoot: string, size: number, frameworks?: readonly string[]) { |
| 231 | for (let i = 0; i < size; i++) { |
no test coverage detected