Commit 3a6310c
perf(runtime): stop sandbox pump loop idle-spinning while awaiting a host call (#3242)
The hook/action runner's pump loop yielded via setImmediate every iteration and
drained the VM job queue. While the body only *waits* on an in-flight host
promise the queue is empty each pass, so the loop woke ~200k×/s doing nothing
(~50k iterations for a 250ms wait — surfaced in the timeout message's pump
count).
Make the yield adaptive: stay on setImmediate while the script is progressing;
once a pump executes zero VM jobs, ramp up to a small capped setTimeout (≤8ms).
Any executed job (a settled host call, a resumed continuation) resets the fast
path, so sequential host calls and multi-turn work keep their low latency —
only a genuinely idle wait backs off, by at most the cap. Deadline enforcement
and every existing pump-budget/timeout/transaction guarantee are unchanged.
Tests: a never-settling host call now reports a bounded pump count (<1000 for a
300ms wait, vs ~50k before); a call that settles at ~120ms — squarely in the
backoff regime — still resolves promptly.
Claude-Session: https://claude.ai/code/session_01BZguyAaQbyUpwMZ2gMLaAP
Co-authored-by: Claude <noreply@anthropic.com>1 parent dd9f223 commit 3a6310c
3 files changed
Lines changed: 88 additions & 2 deletions
File tree
- .changeset
- packages/runtime/src/sandbox
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
741 | 741 | | |
742 | 742 | | |
743 | 743 | | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
221 | 221 | | |
222 | 222 | | |
223 | 223 | | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
224 | 234 | | |
| 235 | + | |
225 | 236 | | |
226 | | - | |
227 | | - | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
228 | 244 | | |
229 | 245 | | |
230 | 246 | | |
| |||
261 | 277 | | |
262 | 278 | | |
263 | 279 | | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
264 | 283 | | |
265 | 284 | | |
266 | 285 | | |
| |||
0 commit comments