perf(mobile): defer audio recorder creation until dictation #15248
t3code/mobile-perf/cache-encoding fromrefs/pull/15248/head·merged by juliusmarminge View on GitHubThe global voice-input provider eagerly constructs Expo's native audio recorder on app launch, even when the user never dictates. Create it on the first recording prepare instead, preserving the global voice session, metering, status events, repeated recordings, and file cleanup. Unmount waits for pending prepare/stop operations before releasing the native object.
Historical evidence before the global voice-provider refactor: a matching iOS 26.5 development client running Hermes opened the same 5,000-message synthetic thread from a 1,003-thread environment. Each capture used a fresh app process. The before capture uses the exact parent implementation; the after capture uses this change.
| Sampled work in a 10-second thread-open capture | Before | After |
|---|---|---|
| AudioRecorder constructor self time | 52.94 ms | 0 ms |
| All non-idle sampled work | 847.53 ms | 851.84 ms |
Those captures demonstrated removal of a cold constructor from the former per-composer path. After rebasing onto the global provider, this change defers app-launch construction instead; the measurements below have not been repeated on the new architecture. Total sampled work did not improve in this single pair, and these development-build traces do not establish an end-to-end navigation speedup. Warm recorder creation was about 3 ms in a separate capture. Eager construction also existed in 1.4; this is an audit hotspot, not a demonstrated cause of the 2.0 regression.
CPU samples, summary and analysis script. Source URLs are stripped from the CPU-only profiles. The recordings show the actual flow; their tap offsets differ, so use the profiles rather than video duration for the numbers above.
Before:
After:
Validation: 47 focused tests pass across the mobile voice-input tests and shared controller tests; mobile typecheck and targeted lint pass. An independent Claude review found no blocking issues. Coverage includes permission denial without allocation, cancellation and file deletion, release after pending stop, failed stop, and recreation after release. The same hook serves thread composers, new-task drafts, and scheduled-task settings. No shared contracts or web/desktop behavior change.
Native recording validation remains incomplete. This simulator has no on-device transcriber, and both the new adapter and the unchanged direct Expo recorder fail with the same native Failed to prepare recorder error after microphone permission succeeds. Android recording has not been exercised. Keep this draft pending a working-device recording check.
Broader audit: version-comparison measurements and limitations. The clean 1.4 run has the same 1,003 synthetic threads and 8,100 messages. Its shell HTTP response was about 30 ms versus 75 ms for current, and Hermes shell decoding was about 164 ms versus 225 ms. The native development captures did not establish a general navigation regression; they are not release-device tap-to-content timings. Current navigation captures already include the cache-encoding layer. A further chunked-cache-decoding experiment was rejected: despite shorter isolated pauses, it delayed first thread rendering during actual cold starts. Its measurements and rejected patch are included in the audit bundle; it is not in this stack.
Implementation and code review: Claude Opus 5.5 through T3 Code's Claude agent. Integration and measurements: GPT-6 Astra through the Codex harness in T3 Code.
Rebase validation: 38 focused voice-input tests passed. Mobile typecheck is blocked locally by missing expo-sensors in DevicePreviewRouteScreen.tsx; no voice-input type errors were reported.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
juliusmarminge added labelsmacroscope-review
Approvability#
Verdict: Not approved
Macroscope's review found this PR not approvable — This performance PR replaces the existing expo-audio hook with a custom lazy native recorder and adds asynchronous release, URI-retention, and listener-management behavior on the production voice-input path. Focused tests cover the helper, but the changed native lifecycle and timing merit validation beyond automated coverage.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
- Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml
- Review profile: CHILL
- Plan: Team
- Run ID:
33ff264e-a63d-4744-bc8e-dd939b9746df
📥 Commits
Reviewing files that changed from the base of the PR and between f06011a4fee59634b6be99f11cfc41e1edf69d7f and 70eecdc300c3769b2f2781dc87a145dacd6238b7.
📒 Files selected for processing (3)
apps/mobile/src/features/voice-input/VoiceInputProvider.tsxapps/mobile/src/features/voice-input/lazyVoiceRecorder.test.tsapps/mobile/src/features/voice-input/lazyVoiceRecorder.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
📝 Walkthrough
Walkthrough#
The voice input provider now uses a lazy adapter to create native audio recorders during preparation. The adapter forwards status updates and delays recorder release until pending operations settle. Tests cover recorder reuse, release behavior, permission denial, and cancellation.
Changes#
Voice recorder lifecycle
Layer / File(s) Summary Lazy recorder lifecycle
apps/mobile/src/features/voice-input/lazyVoiceRecorder.ts,apps/mobile/src/features/voice-input/lazyVoiceRecorder.test.tsThe adapter creates the native recorder during preparation and releases it after pending operations settle. Tests cover preparation, reuse, status forwarding, release, and failed stops. Provider wiring and controller behavior
apps/mobile/src/features/voice-input/VoiceInputProvider.tsx,apps/mobile/src/features/voice-input/lazyVoiceRecorder.test.tsThe provider selects platform recording options, forwards recorder status to the controller, and releases the recorder during cleanup. Controller tests cover denied permission and cancellation. Priority: ⬇️ Low
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Refactor
Sequence Diagram(s)#
sequenceDiagram participant VoiceInputProvider participant LazyVoiceRecorder participant AudioModule.AudioRecorder participant VoiceInputController VoiceInputProvider->>LazyVoiceRecorder: create recorder with platform options LazyVoiceRecorder->>AudioModule.AudioRecorder: create native recorder on preparation AudioModule.AudioRecorder->>VoiceInputController: forward recorder status VoiceInputProvider->>VoiceInputController: dispose controller VoiceInputProvider->>LazyVoiceRecorder: release recorderMerge Risk: ⚪ Minimal · up to
70eecNo concrete merge-blocking regression was established. Recording still needs validation on a working device before release.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
Check name Status Explanation Resolution Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold. ✅ Passed checks (4 passed)
Check name Status Explanation 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. Title check ✅ Passed The title clearly and concisely describes the main change: defer mobile audio recorder creation until dictation. Description check ✅ Passed The description explains the problem and change, defines scope, and gives detailed verification results and limitations. It does not identify a triaged issue or maintainer approval, or explain why the… - Fix all pre-merge checks with AI
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
- Commit to this branch
- Create a new PR
🛠️ Fix failing CI checks 💡
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
- Commit to this branch
- Create a new PR
- Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment `@coderabbitai help` to get the list of available commands.juliusmarminge merged thisc71ca06
juliusmarminge closed this
Sign in to join this conversation.
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline: unavailable · PR result:
70eecdc· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.