Skip to content

Keep the local Whisper model resident between dictations - #13

Merged
ichen27 merged 1 commit into
mainfrom
fix/stt-cold-start-latency
Nov 12, 2026
Merged

ichen27 merged 1 commit into
mainfrom
fix/stt-cold-start-latency

Conversation

@ichen27

@ichen27 ichen27 commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Problem

Dictation latency was inconsistent. On a 16 GB Apple Silicon Mac under memory pressure (about 8.7 GB of swap in use), the first request to an idle local Whisper service took 14.2 s for a 7.5 s clip. The next requests took 0.96–1.1 s. vmmap showed the service at a 3.9 GB footprint, with most of the model's Metal buffers swapped out. Two causes:

  • MLX keeps freed activation buffers cached, roughly doubling the idle footprint beyond the 1.5 GB of weights.
  • Nothing stops macOS from paging out the idle model. The LaunchAgent also ran as ProcessType: Background, so launchd throttles the service's CPU and disk I/O, including paging the model back in.

Change

  • server.py
    • Caps the MLX buffer cache at 256 MiB.
    • After warm-up, calls mx.set_wired_limit(peak + 256 MiB), capped at 90% of the system's recommended working set, so the model can't be paged out. Whisper always decodes padded 30 s windows, so the warm-up peak matches a real request.
    • CLEARFLOW_KEEP_RESIDENT=0 opts out. The ready log line reports the wired size.
  • install-agent.py: ProcessType changes from Background to Interactive.
  • local-stt/README.md: documents the memory trade-off (about 2.3 GB kept resident).

Validation

  • python3 -m unittest discover -s local-stt passes (22 tests), including new checks for the wired-limit calculation and the agent's process type.
  • On an M4 with 16 GB, the patched server reported wiredMiB: 2295. Footprint dropped from 3.9 GB to 1.9 GB, and warm latency held at 0.92–0.97 s.
  • Not yet shown: that this removes the cold start. After 25 minutes idle, both the old and the patched server still answered warm (1.49 s and 1.25 s), so the slow first request needs a longer idle period or more pressure. The fix follows from the measured cause, but it isn't proven by a before/after run. Confirm it by deploying and timing the first dictation after a long idle.

Risks

  • About 2.3 GB stays wired, so other apps on a 16 GB Mac have that much less memory to page into. Set CLEARFLOW_KEEP_RESIDENT=0 to trade back.
  • Existing LaunchAgents keep Background until install-agent.py is rerun.

Under memory pressure macOS paged the idle model out, so the first request
after a quiet period took 14 s instead of about 1 s. Wire the warm-up working
set with MLX, cap the idle buffer cache (3.9 GB -> 1.9 GB footprint), and stop
running the LaunchAgent as throttled Background work.
@ichen27
ichen27 merged commit 14a8482 into main Nov 12, 2026
3 checks passed
@ichen27
ichen27 deleted the fix/stt-cold-start-latency branch November 12, 2026 05:52
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