Open & local AI

Optimizing local LLM latency on Apple Silicon with caching and pattern matching

A deep dive into homie, a voice assistant that reduces inference lag by skipping the model for common tasks and caching system prompts to avoid re-reading tokens.

Illustration of a laptop with AI processing visualized as gears and neural networks
Illustration generated for this article

Saif Ali recently detailed the engineering behind homie, a voice assistant designed to run entirely on Apple Silicon Macs. Published in late November 2026, the project demonstrates how to make a 4-billion parameter language model feel instantaneous by aggressively optimizing inference latency and managing memory constraints on devices like the M5 chip.

What happened

The core challenge was not getting the model to work, but making it feel fast enough for voice interaction. On an M5 Mac with 16 GB of RAM, the Qwen 3.5 4B model generates between 15 and 30 tokens per second, a rate that fluctuates significantly under memory pressure. Since tool calls must be generated token by token, simple requests like setting a timer could take two to five seconds, creating an unacceptable delay for users.

To solve this, the developer implemented two primary rules: do not invoke the language model when unnecessary, and never force the model to re-read its instructions. The resulting system, homie, lives in the MacBook notch and handles tasks like setting timers, playing music, and reading calendars without internet access. It combines Qwen 3.5 4B via llama.cpp for reasoning, Kokoro-82M on the Neural Engine for voice synthesis, and Apple’s on-device speech recognition.

How it works

The system uses a hybrid approach to minimize latency. An "instant lane" consisting of about 600 lines of pattern-matching code intercepts common commands such as opening apps or checking calendar events. These patterns execute in roughly one millisecond and have been tuned to avoid false positives, achieving perfect accuracy on a test set of 214 phrases. Commands that do not match these patterns are passed to the language model.

For the model itself, the system avoids re-processing the 3,700-token system prompt on every turn. Instead, it saves the model state to disk after the initial load, allowing subsequent queries to only process new user input. This reduced launch-to-ready time from several seconds to 0.12 seconds. Additionally, the voice output begins before the model finishes generating the full response, cutting the time to first sound from 1.49 seconds to 0.88 seconds by streaming audio at natural phrase breaks.

Key details

  • Pattern matching handles 87% of initial test cases and now covers 214 specific phrasings with zero errors, bypassing the LLM for routine tasks.
  • Prompt caching saves the model state after reading the system prompt, reducing per-turn token processing from 3,700 to approximately 45 tokens.
  • Sorting JSON keys in tool definitions ensured byte-identical prompts across launches, fixing persistent cache misses that had previously slowed performance.
  • Voice activity detection waits 0.25 seconds of silence before starting inference, allowing the model to begin processing while the user is still finishing their sentence.
  • Screen interaction relies on Apple’s Accessibility tree and text recognition to locate elements, rather than asking the 4B model to generate coordinates, which proved unreliable.
  • Speculative decoding and switching to the MLX framework were tested but rejected because they offered negligible speed gains or increased complexity without benefit.

Why it matters

This project highlights that raw token generation speed is less critical than architectural efficiency for local AI applications. By offloading deterministic tasks to rule-based systems and maintaining a stable prompt cache, developers can achieve sub-second response times even on hardware with limited memory bandwidth. This approach challenges the assumption that larger models or more complex inference engines are always necessary for responsive user experiences.

For engineers building on-device AI, the findings emphasize the importance of data consistency in caching strategies. Small implementation details, such as the order of dictionary keys in JSON serialization, can invalidate caches and destroy performance gains. Furthermore, the decision to keep a single, stable tool list rather than filtering tools per request shows that theoretical optimizations often fail in practice due to overhead costs.

What you can do

  • Implement a rule-based fallback layer for high-frequency, low-complexity commands to reduce reliance on expensive model inference.
  • Ensure prompt strings are byte-identical across sessions by sorting keys in structured data like JSON to maintain effective prompt caching.
  • Start audio playback at natural linguistic breaks rather than waiting for complete sentence generation to improve perceived responsiveness.
  • Use native OS accessibility APIs for screen coordinate tasks instead of relying on small language models to predict spatial locations.
  • Test speculative decoding carefully, as rewind costs in hybrid models may outweigh the benefits of faster draft generation.
  • Monitor network usage to verify that local models remain isolated, using tools like lsof to confirm no unexpected external connections are made.
  • #apple silicon
  • #llm optimization
  • #local ai
  • #latency
  • #voice assistants

Tools from the Bytechap store

$89

DocBento

Self-hosted document management that reads every scan and answers with page citations.

Live demo

Keep reading

All stories