Skip to content

perf(recording): wake the audio mixer on input instead of polling every 5 ms - #2764

Open
richiemcilroy wants to merge 3 commits into
mainfrom
perf/audio-mixer-wait-on-input
Open

richiemcilroy wants to merge 3 commits into
mainfrom
perf/audio-mixer-wait-on-input

Conversation

@richiemcilroy

@richiemcilroy richiemcilroy commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

What

The audio mixer's run loop slept a fixed 5 ms between ticks for the whole recording, about 200 wakeups/s. Most ticks found nothing new.

Now:

  • Input wakes the mixer. Input channels are polled with a waker that unparks the mixer thread (poll_next_unpin instead of try_next; the same empty/ready/closed semantics), so a producer's send wakes it straight away.
  • Idle wait. With no input, it waits park_timeout(idle_wait()): half the shortest source buffer timeout, clamped to 5–25 ms (10 ms for a wired mic's 20 ms minimum). A source that goes quiet is still filled with silence, and stalls are still observed, within half its timeout.
  • Unchanged: output placement stays sample-based, so tick timing doesn't move audio. The stop/drain path (finish) is untouched.

Expected effect: the mixer ticks per input frame (tens per second for a mic, ~100 for system audio) plus the occasional idle timeout, instead of a fixed 200/s, and input is processed up to 5 ms sooner.

Proof

  • Unit tests:
    • input_wake::a_frame_arriving_after_a_drain_wakes_the_mixer
    • input_wake::idle_wait_is_half_the_shortest_buffer_timeout_within_bounds
  • A/V sync and real-capture A/B against main: the Verify recording dispatch runs are linked in the comments below.

No Hona-authored lines are touched.

RetriggerView in GreptileConfidence Score: 4/5

Remove the comment on input_waker before merging to satisfy the repository’s comments policy.

Findings

  1. P2 Comment breaks repository policy ▶
Fix with agent prompt
### Issue 1
crates/recording/src/sources/audio_mixer.rs:235-236
The comment on `input_waker` describes what the new code does. `AGENTS.md` bans comments that narrate code or describe the current change. Remove this comment before merging to satisfy that requirement.

```suggestion

```

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR wakes the audio mixer when input arrives instead of sleeping for 5 ms after every tick.

  • Audio input wakes the mixer instead of waiting for a fixed tick.

Reviews (2) · Last reviewed commit: "chore(recording): drop the comment that ..." · Reviewed by Greptile

@vercel

vercel Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cap-status Ready Ready Preview Oct 22, 2026 10:06am UTC

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Greptile has paused reviews on this repository — it used its 1000 free open-source review credits for this billing period. Reviews resume automatically on October 26. To continue before then, an organization admin can keep reviews running past the free credits — those bill as normal usage.

@capy-ai capy-ai 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.

Capy found no issues.

View 2 other findings in Capy.

Open in Capy

@richiemcilroy

Copy link
Copy Markdown
Member Author

@greptileai review

1 similar comment
@richiemcilroy

Copy link
Copy Markdown
Member Author

@greptileai review

Comment on lines +1129 to +1130
/// Wakes the mixer thread from `park_timeout` when an input channel has a
/// frame.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Comment repeats the code

The new comment on ThreadUnpark only restates what its wake methods do. AGENTS.md bans comments that narrate the code rather than explain non-obvious context. Remove this comment before merging to satisfy that requirement; the type name and methods already explain it.

Suggested change
/// Wakes the mixer thread from `park_timeout` when an input channel has a
/// frame.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/recording/src/sources/audio_mixer.rs
Line: 1129-1130

Comment:
**Comment repeats the code**

The new comment on `ThreadUnpark` only restates what its `wake` methods do. `AGENTS.md` bans comments that narrate the code rather than explain non-obvious context. Remove this comment before merging to satisfy that requirement; the type name and methods already explain it.

```suggestion

```

**Context Used:** AGENTS.md ([source](https://github.com/capsoftware/cap/blob/main/AGENTS.md))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@richiemcilroy

Copy link
Copy Markdown
Member Author

@greptileai review

@capy-ai capy-ai 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.

Capy found no issues.

Open in Capy

Comment on lines +235 to +236
/// Registered on every input channel, so a frame arriving wakes the mixer
/// thread instead of waiting for its next poll.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Comment breaks repository policy

The comment on input_waker describes what the new code does. AGENTS.md bans comments that narrate code or describe the current change. Remove this comment before merging to satisfy that requirement.

Suggested change
/// Registered on every input channel, so a frame arriving wakes the mixer
/// thread instead of waiting for its next poll.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/recording/src/sources/audio_mixer.rs
Line: 235-236

Comment:
**Comment breaks repository policy**

The comment on `input_waker` describes what the new code does. `AGENTS.md` bans comments that narrate code or describe the current change. Remove this comment before merging to satisfy that requirement.

```suggestion

```

**Context Used:** AGENTS.md ([source](https://github.com/capsoftware/cap/blob/main/AGENTS.md))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@blacksmith-sh

blacksmith-sh Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Found 2 test failures on Blacksmith runners:

Failures

Test View Logs
cap-verify::crash/crash_safety View Logs
cap-verify::crash/crash_safety View Logs

Fix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

@capy-ai capy-ai 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.

Capy found no issues.

Open in Capy

This branch was successfully deployed

2 active deployments
Preview – cap-web — 8e5e5072 Deployed Oct 22, 2026 by vercel[bot]
Preview – cap-status — 8e5e5072 Deployed Oct 22, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant