RUNLOCALAIv38
->Will it run?Best GPUCompareTroubleshootStartLearnPulseModelsHardwareToolsBench
Run check
RUNLOCALAI

Independently operated catalog for local-AI hardware and software. Hand-written verdicts. Source-cited claims. Reproducible commands when we have them.

OP·Eruo Fredoline
DIR
  • Models
  • Hardware
  • Tools
  • Benchmarks
TOOLS
  • Will it run?
  • Compare hardware
  • Cost vs cloud
  • Choose my GPU
  • Prompting kits
  • Quick answers
REF
  • All buyer guides
  • Learn local AI
  • Methodology
  • Glossary
  • Errors KB
  • Trust
EDITOR
  • About
  • Author
  • How we make money
  • Editorial policy
  • Contact
LEGAL
  • Privacy
  • Terms
  • Sitemap
MAIL · MONTHLY DIGEST
Get monthly local AI changes
Monthly recap. No spam.
DISCLOSURE

Some links on this site are affiliate links (Amazon Associates and other first-class retailers). When you buy through them, we earn a small commission at no extra cost to you. Affiliate links do not influence our verdicts — there are cards we rate highly that we don't have affiliate relationships with, and cards that sell well that we refuse to recommend. Read more →

© 2026 runlocalai.coIndependently operated
RUNLOCALAI · v38
  1. >
  2. Home
  3. /Learn
  4. /Courses
  5. /Local AI on macOS
  6. /Ch. 9
Local AI on macOS

09. Performance Tuning

Chapter 9 of 15 · 15 min
KEY INSIGHT

Reducing context window is the single highest-leverage performance tuning on Apple Silicon—smaller contexts use less memory and run faster.

Performance tuning on Apple Silicon has two levers: memory allocation and batch sizing. Everything else is secondary.

Memory headroom is the first tuning step. If your model is consuming 90% of RAM, reduce the context window. In Ollama:

# Run with a reduced context
ollama run llama3.2:3b -c 1024   # 1024 max context tokens instead of default 2048+

# Or set in the API
curl -X POST http://localhost:11434/api/generate \
  -d '{"model":"llama3.2:3b","prompt":"Hello","options":{"num_ctx":1024}}'

A smaller context window directly reduces memory usage. The KV cache (which stores context state) scales roughly linearly with context length. Cutting from 4096 to 1024 tokens can reduce memory pressure by 70% and boost throughput by 2–3×.

The second lever is batch size, which controls how many tokens are processed in parallel before returning results. In llama.cpp-based runtimes (including Ollama), batch size is controlled via numa settings and thread count:

# Ollama environment tuning
export OLLAMA_NUM_PARALLEL=4      # max concurrent requests
export OLLAMA_MAX_LOADED_MODELS=1  # only one model at a time
export OLLAMA_GPU_OVERHEAD=0       # minimal VRAM reservation

# For llama.cpp CLI
./quantize model.gguf --output model-q4km.gguf Q4_K_M
./main -m model-q4km.gguf -c 2048 -t 8 -ngl 99
# -t 8: use 8 CPU threads
# -ngl 99: offload all layers to GPU (Metal)

Real failure mode: setting -ngl 99 on an M1 with 8 GB causes OOM because all layers in a 7B model require more GPU memory than is available. Start with -ngl 1 (offload one layer at a time) or explicitly limit with -ngl 32 for a 32-layer model on a constrained chip.

GPU temperature management matters on MacBooks. Metal performance throttles when thermal limits are reached. You cannot change the thermal management, but you can reduce sustained load by limiting batch sizes or using a slightly smaller model.

EXERCISE

Run a model at two different context sizes (e.g., 512 and 2048) and measure tokens per second. Calculate the percentage improvement and relate it to your memory utilization from Activity Monitor.

← Chapter 8
Mac Model Selection Guide
Chapter 10 →
Activity Monitor for AI