Skip to content

perf(worklet): rate-limit the under-run position nudge (fix stutter feedback loop) - #42

Open
ahonnecke wants to merge 2 commits into
got-feedBack:mainfrom
ahonnecke:perf-underrun-rate-limit
Open

perf(worklet): rate-limit the under-run position nudge (fix stutter feedback loop)#42
ahonnecke wants to merge 2 commits into
got-feedBack:mainfrom
ahonnecke:perf-underrun-rate-limit

Conversation

@ahonnecke

@ahonnecke ahonnecke commented Jul 27, 2026

Copy link
Copy Markdown

Problem

The urgent under-run position nudge was posted per 128-sample quantum (~344 Hz), flooding the main thread and starving the refill pump — a positive-feedback stutter loop.

Fix

Cap urgent posts to ~100 Hz via _urgentInterval. One file (assets/stretch-worklet.js), +11/-1.

main's worklet doesn't currently have this rate-limit. Low-risk, worklet-only.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Performance Improvements
    • Reduced excessive position updates during streaming interruptions.
    • Improved playback stability by rate-limiting urgent buffer refill updates, including smoother handling of the first urgent under-run after streaming begins.

…oop)

The urgent under-run nudge posted per 128-sample quantum (~344Hz), flooding the
main thread and starving the refill pump — a positive-feedback stutter loop.
Cap urgent posts to ~100Hz (_urgentInterval).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 24129773-71a2-4423-9755-339ffe4dab98

📥 Commits

Reviewing files that changed from the base of the PR and between c7e17f4 and 768ef13.

📒 Files selected for processing (1)
  • assets/stretch-worklet.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • assets/stretch-worklet.js

📝 Walkthrough

Walkthrough

The audio worklet rate-limits urgent under-run refill position notifications, while preserving an immediate post when the stream first enters an under-run state.

Changes

Position post throttling

Layer / File(s) Summary
Interval selection and urgent-state posting
assets/stretch-worklet.js
Initializes _urgentInterval, _posAccum, and _wasUrgent; _maybePostPos uses urgent or steady-state thresholds and posts immediately when urgent state begins.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: rate-limiting urgent under-run nudges in the worklet to reduce stutter.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@assets/stretch-worklet.js`:
- Around line 345-349: Update the position-posting logic around the urgent
threshold check to track the previous urgent state and detect entry into urgent
mode. Send the first urgent notification immediately on that transition, even
when _posAccum is below _urgentInterval; continue applying _urgentInterval to
subsequent urgent posts and preserve the existing steady-state behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8db6b9db-5216-455d-951a-706f42f25659

📥 Commits

Reviewing files that changed from the base of the PR and between 7082b23 and c7e17f4.

📒 Files selected for processing (1)
  • assets/stretch-worklet.js

Comment thread assets/stretch-worklet.js Outdated
…ot-feedBack#42)

The rate-limit also swallowed the first urgent nudge on entering an under-run,
so a short under-run could get no refill notification for ~10ms. Track the
urgent-state transition and post immediately on entry; throttle only subsequent
urgent posts.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant