Issue #207 — On-Device Core ML Inference & Battery-Safe Mobile ML
Running machine learning models locally on iOS eliminates server costs and protects user privacy — two huge advantages for indie apps. Issue #207 examined practical Core ML optimization techniques so models stay responsive without spiking thermal state.
Compute Unit Selection & Quantization Trade-offs
| Precision / Target | Model Size | Typical Latency (A15+) | Best Use Case |
|---|---|---|---|
FP32 (.all) | 100% baseline | 18–35 ms | Scientific / high-precision regression |
FP16 (.cpuAndNeuralEngine) | ~50% smaller | 4–9 ms | Vision classification, OCR, image tagging |
| INT8 Weight Palettization | ~25% smaller | 3–7 ms | App-bundle-sensitive indie utilities |
Always Guard Compute Units & Load Asynchronously
Never compile or instantiate an MLModel synchronously on the main thread during app launch. Use the async loader and configure compute units explicitly (see MLModelConfiguration):
let config = MLModelConfiguration()
config.computeUnits = .cpuAndNeuralEngine
let model = try await ImageClassifier.load(configuration: config)