* 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,
beforeStart?: () => void
)
| 226 | * pool is going to start, before any worker opens the database. |
| 227 | */ |
| 228 | static tryCreate( |
| 229 | dbPath: string, |
| 230 | projectRoot: string, |
| 231 | frameworks?: readonly string[], |
| 232 | worth?: number, |
| 233 | beforeStart?: () => void |
| 234 | ): ResolverPool | null { |
| 235 | if (process.env.CODEGRAPH_NO_PARALLEL_RESOLVE === '1') return null; |
| 236 | const workerScript = path.join(__dirname, 'resolver-worker.js'); |
| 237 | if (!fs.existsSync(workerScript)) return null; |
| 238 | let dbSizeBytes = 0; |
| 239 | try { |
| 240 | dbSizeBytes = fs.statSync(dbPath).size; |
| 241 | } catch { /* fresh/missing file — the 256MB per-worker floor applies */ } |
| 242 | const ap = os.availableParallelism(); |
| 243 | const budget = memoryBudgetBytes(); |
| 244 | const size = ResolverPool.resolvePoolSize({ |
| 245 | explicit: process.env.CODEGRAPH_RESOLVE_WORKERS, |
| 246 | availableParallelism: ap, |
| 247 | memoryBudget: budget, |
| 248 | dbSizeBytes, |
| 249 | worth, |
| 250 | }); |
| 251 | // Both outcomes log under SYNTH_TIMINGS — a silent null is how §7a.1's |
| 252 | // diagnostic run hid the memory-term misfire for a whole 25-minute cycle. |
| 253 | if (process.env.CODEGRAPH_SYNTH_TIMINGS) { |
| 254 | console.error( |
| 255 | `[pool-timing] pool ${size === null ? 'disabled' : `size=${size}`} (ap=${ap} budget=${Math.round(budget / 1024 / 1024)}MB db=${Math.round(dbSizeBytes / 1024 / 1024)}MB)` |
| 256 | ); |
| 257 | } |
| 258 | if (size === null) return null; |
| 259 | beforeStart?.(); |
| 260 | try { |
| 261 | return new ResolverPool(workerScript, dbPath, projectRoot, size, frameworks); |
| 262 | } catch { |
| 263 | return null; |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | private constructor(workerScript: string, dbPath: string, projectRoot: string, size: number, frameworks?: readonly string[]) { |
| 268 | for (let i = 0; i < size; i++) { |
no test coverage detected