Skip to content

Worklet: come back down quickly after a stall - #12

Merged
bdbarnett merged 1 commit into
mainfrom
ostinato/queue-recovery
Oct 15, 2026
Merged

bdbarnett merged 1 commit into
mainfrom
ostinato/queue-recovery

Conversation

@bdbarnett

Copy link
Copy Markdown
Contributor

A single stall used to push the audio queue straight to its maximum, because every short quantum added 512 frames. It then held there for ten seconds and stepped down 256 frames every two seconds, so a 0.3 s stall cost about half a minute of extra latency.

Now a stall raises the target at most every quarter second and holds it for two seconds. After that, if the low point over two seconds shows 512 frames or more to spare, the target drops by what was spare in one step. Stalls that keep coming within ten seconds of each other still hold for ten.

tests/worklet_sim.mjs runs the worklet in Node against a worker that stalls or replies late. Two new tests use it:

  • After a 0.3 s stall, the queue now peaks at 1792 frames instead of 4096 and is back at its floor about 2 s after the stall ends, instead of 34 s. This test fails on the old worklet.
  • With replies arriving late at random for a minute, the queue stays up and dropouts stay few. This guards against dropping back too eagerly.

In a browser app with an engine overloaded on purpose, the queue went back to its floor 3 to 4 s after the last underrun.

One stall used to push the queue straight to its maximum (every short
quantum added 512 frames) and hold it there ten seconds, then step down 256
frames every two seconds: a 0.3 s stall cost half a minute of extra latency.
Now a stall raises the target at most every quarter second and holds two
seconds; then, when the low point over two seconds shows 512 frames or more
to spare, the target drops by what was spare in one step. Stalls that keep
coming within ten seconds still hold ten. tests/worklet_sim.mjs runs the
worklet in node against a worker that stalls or replies late.
@bdbarnett
bdbarnett merged commit 78e2d4d into main Oct 15, 2026
1 check passed
@bdbarnett
bdbarnett deleted the ostinato/queue-recovery branch October 15, 2026 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant