()
| 333 | } |
| 334 | |
| 335 | private shrinkIdle(): void { |
| 336 | this.idleShrinkTimer = undefined; |
| 337 | if (!this.quiescent) return; |
| 338 | |
| 339 | // Keep one worker, trimmed in place, rather than ending them all and |
| 340 | // starting a clean one. A clean worker has to work out again everything a |
| 341 | // connection remembers (the dominant file, the name indexes): half a second |
| 342 | // on the next call on a mid-sized index, seconds on a large one. The trim |
| 343 | // leaves this one about 70 MB above a clean worker, on any index. Staying |
| 344 | // up also means no moment here when a call finds no worker. |
| 345 | const keep = this.lastServer && this.idle.includes(this.lastServer) |
| 346 | ? this.lastServer |
| 347 | : this.idle[this.idle.length - 1]; |
| 348 | if (!keep) return; |
| 349 | for (const w of this.idle) { |
| 350 | if (w === keep) continue; |
| 351 | this.workers.delete(w); |
| 352 | this.retire(w); |
| 353 | } |
| 354 | this.idle = [keep]; |
| 355 | this.servedSinceShrink = false; |
| 356 | try { |
| 357 | keep.postMessage({ type: 'trim' }); |
| 358 | } catch { /* already gone: its 'exit' recovers the pool */ } |
| 359 | } |
| 360 | |
| 361 | /** |
| 362 | * The last check on a kept worker: one that still holds a lot after its trim |
no test coverage detected