perf: reduce perceived recording start delay by ~50%#229
perf: reduce perceived recording start delay by ~50%#229JereSalo wants to merge 2 commits intoaltic-dev:mainfrom
Conversation
Previously the overlay expand animation only started after the engine was fully initialized (triggered by isRunning becoming true). This adds showOverlayEarly() which fires the overlay immediately on hotkey press, so the ~300ms expand animation runs concurrently with engine startup instead of sequentially after it. Applied to dictation, command, and rewrite mode callbacks.
Instead of destroying and recreating the AVAudioEngine on every stop(), keep it stopped but allocated. This avoids the expensive inputNode and outputNode instantiation on subsequent starts (~200ms saved). The engine format is re-negotiated cleanly via prepare() + start(), and device changes are handled by bindPreferredInputDeviceIfNeeded() in startEngine().
|
Hi! I made this PR just because I upgraded to 1.5.9 and though it's fast once you finish speaking at the beginning I found it kinda sluggish, taking almost a whole second from when I pressed option and I saw the animation to start talking, so I made a few changes regarding this, the most important one is initiating the UI and the engine concurrently so that we don't need to wait for the engine to load till we load the UI. This works fine because the UI initialization is not very fast. |
|
@JereSalo thanks! please do use it for a couple days and lmk how it goes. The issue is it might work for you and i but will cause issues for others with different devices etc. so I made that. delay to be safe. But down to check this out once you think it's stable :) |
Summary
Reduces the perceived delay between pressing the hotkey and seeing the recording overlay by ~50%, from ~850ms to ~400-450ms. Two independent optimizations:
1. Show overlay in parallel with engine startup (
1c2ca54)Previously, the overlay expand animation only started after the audio engine was fully initialized, because it was triggered by
isRunningbecomingtrue. This addsshowOverlayEarly()which fires the overlay immediately on hotkey press, so the ~300ms expand animation runs concurrently with the ~330ms engine startup instead of sequentially after it. The overlay doesn't need the engine to be ready — it only needs theaudioLevelPublisher, which simply emits no values until the engine starts capturing. Applied to dictation, command, and rewrite mode callbacks.2. Keep audio engine alive between recordings (
dd2c73d)Previously,
stop()destroyed theAVAudioEngineinstance and the nextstart()had to recreate it from scratch, including the expensiveinputNode(~166ms) andoutputNode(~36ms) instantiation where CoreAudio creates the aggregate device. Nowstop()just callsengine.stop()and keeps the instance in memory. On the nextstart(), the nodes are already instantiated soconfigureSession()is near-instant, and onlyprepare()+start()need to run. Device changes between recordings are handled normally because in sync mode the engine follows the system default device, andprepare()re-negotiates the audio format with whatever device is currently active.Measured results
Engine startup time (hotkey callback to
isRunning = true):Total perceived delay (Option key press to overlay fully visible):