Commit 7b93a92
committed
wasm: keep one pending scheduler wakeup instead of leaking a timer chain
sleepTicks armed a fresh setTimeout on every call and never cancelled the
previous one. Its callback calls go_scheduler(), which re-enters the scheduler,
which calls sleepTicks again whenever it finds nothing runnable but something
sleeping — so every armed timer replaces itself, and every JS->Go callback that
reaches the scheduler starts another such chain. The pending count grows without
bound.
The scheduler only needs one pending wakeup, the earliest. Track it, and drop
any request that is no sooner than what is already armed.
Measured in Chrome with the same wasm binary, 50 sleeping goroutines and a
requestAnimationFrame loop, counting setTimeout calls per second at three
points: 487/1498/2509 before, 9/5/5 after. Go-side timing is unchanged (a
goroutine sleeping in a loop still advances 3s over 3s of wall clock) and frame
pacing is unchanged at ~59fps.
Fixes #56211 parent 3948846 commit 7b93a92
1 file changed
Lines changed: 18 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
270 | 270 | | |
271 | 271 | | |
272 | 272 | | |
273 | | - | |
274 | | - | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
275 | 284 | | |
276 | 285 | | |
277 | 286 | | |
278 | 287 | | |
279 | 288 | | |
280 | 289 | | |
281 | | - | |
| 290 | + | |
282 | 291 | | |
283 | 292 | | |
284 | 293 | | |
| |||
489 | 498 | | |
490 | 499 | | |
491 | 500 | | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
492 | 507 | | |
493 | 508 | | |
494 | 509 | | |
| |||
0 commit comments