()
| 98 | |
| 99 | // Time-based yield: only yield every ~100ms of wall time instead of every N iterations. |
| 100 | // In foreground tabs setTimeout(0) costs ~4ms; in background tabs it's throttled to ~1s. |
| 101 | // By yielding based on elapsed time we get ~10 yields per second in foreground (smooth progress) |
| 102 | // and minimal extra delay in background (~10 yields × 1s = ~10s overhead instead of ~200s). |
| 103 | let _lastYieldTime = 0; |
| 104 | function _shouldYield() { |
| 105 | const now = performance.now(); |