Docs /Performance & Thermal Tuning
ENGINEERING GUIDE · PERFORMANCE & THERMALS

Performance & Thermal Tuning.

Extract peak token generation speeds and maximize battery efficiency on Android. Learn how ARM DynamIQ CPU topology, memory-mapped I/O (mmap), thermal mitigation curves, and KV cache sizing prevent stalls and overheating.

Real-World Chipset Benchmarks (Q4_K_M)

Measured on production ARM64-v8a llama.cpp runtime under 22°C ambient room temperature with 4 performance threads:

SoC / ProcessorTested Devices3B Model Speed7B Model SpeedBattery / 1k TokensThermal Profile
Snapdragon 8 Gen 3 (Adreno 750 / Cortex-X4)Galaxy S24 Ultra, OnePlus 1242 – 55 tok/s18 – 24 tok/s0.8% – 1.1%Excellent (Vapor Chamber keeps under 42°C)
Snapdragon 8 Gen 2 (Adreno 740 / Cortex-X3)Galaxy S23, Nothing Phone 232 – 44 tok/s14 – 18 tok/s1.0% – 1.4%Very Good (Stable 4-thread execution)
Google Tensor G3 / G4 (Mali-G715)Pixel 8 Pro, Pixel 926 – 36 tok/s11 – 15 tok/s1.2% – 1.6%Moderate (Throttle kicks in after 4 mins)
Dimensity 8020 / 7200 (Mid-Range)Nothing Phone 2a, Redmi Note 13 Pro20 – 28 tok/s8 – 11 tok/s1.4% – 1.9%Warm (Recommend 3B and 1.5B models)

ARM big.LITTLE / DynamIQ CPU Topology & Thread Scheduling

Why setting your thread count equal to the number of Performance cores (typically 4) yields higher tokens per second and drastically reduced thermal dissipation compared to saturating all 8 virtual cores.

The Heterogeneous Cluster Problem: Thread Synchronization Stalls

Modern mobile SoCs (like Snapdragon 8 Gen 3, Dimensity 9300, and Google Tensor G4) organize CPU cores into heterogeneous clusters managed by ARM DynamIQ technology. A typical 8-core silicon floorplan divides as follows:

1× Prime Core

Cortex-X4 @ 3.3 GHz. Maximum IPC and wide NEON/SVE2 vector execution, but consumes high power per clock cycle.

3–5× Performance Cores

Cortex-A720 @ 3.0 GHz. Optimized balance of high floating-point throughput, large L2 cache, and thermal efficiency.

2–4× Efficiency Cores

Cortex-A510 / Cortex-A520 @ 2.0–2.2 GHz. Stripped-down in-order pipeline with narrow 64-bit vector units designed for background tasks.

Why Spawning 8 Threads Destroys Token Throughput:

In llama.cpp and GGML tensor runtimes, matrix multiplications (GEMM/GEMV) are partitioned into equal row slices across active worker threads. At the end of each tensor layer, all threads must synchronize at a pthread barrier:

  • The Stalled Barrier: If you configure 8 threads, 2–4 threads are assigned to slow Cortex-A510/A520 efficiency cores. The fast Prime and Performance threads finish their row tile computation in ~4 milliseconds, but must then busy-wait or sleep for 18+ milliseconds waiting for the slow efficiency cores to complete their slice.
  • Wasted Joules: The fast cores burn energy idling at the barrier while the efficiency cores operate near 100% capacity at low vector throughput, producing higher overall heat for lower net tokens/sec.
  • The 4-Thread Golden Rule: Pinning Local AI to 4 threads confines all matrix math strictly to the Cortex-X prime and Cortex-A7xx performance cores. Work distribution finishes synchronously, eliminating thread barrier stalls and delivering 15% to 30% higher net token speed.

Memory-Mapped I/O (mmap) Deep Dive

How Linux kernel virtual memory page tables allow Local AI to load multi-gigabyte models in under 1.5 seconds without copying weights byte-by-byte into resident RAM.

Standard File Allocation (malloc + fread)
  • App allocates 3.8 GB of physical RAM heap via malloc().
  • App issues synchronous read() system calls reading the entire GGUF file from UFS storage.
  • Startup Latency: 12 to 18 seconds before the first prompt can be entered.
  • OOM Risk: Kernel treats every allocated page as dirty memory, triggering aggressive Android LMK SIGKILL if headroom drops.
Memory-Mapped I/O (mmap - MAP_SHARED)
  • Kernel creates virtual memory area (VMA) mappings in the process page table pointing to GGUF disk offsets.
  • Zero initial physical memory is consumed; weights are loaded on demand via minor page faults.
  • Startup Latency: Under 1.5 seconds to ready state.
  • Zero Swap Thrash: File-backed clean pages can be discarded instantly by the kernel if another app needs RAM, avoiding crash kills.

Virtual Address Space (VIRT) vs Resident Set Size (RSS)

When you monitor Local AI in Android Studio Profiler or ADB, you will observe the process VIRT (Virtual Memory) size immediately jump to ~4.5 GB, while RSS (Resident Set Size) remains small. As tokens are generated, only the specific weight matrices currently involved in attention projection and feed-forward layers are paged into physical RAM. This allows the OS page cache to intelligently prioritize active tensors.

Thermal Throttling Curves & Mitigation Techniques

Smartphones dissipate heat through passive conduction into the aluminum frame and vapor chambers. Understanding CPU junction temperatures prevents performance cliffs.

The 4 Stages of the Mobile Thermal Throttle Curve

Stage 1: Ambient Peak (< 65°C Junction)100% Clock Frequency · 45–55 tok/s
Stage 2: Sustained Load (65°C – 74°C Junction)Cortex-X4 downclocks by 15% · 38–44 tok/s
Stage 3: Thermal Boundary (75°C – 80°C Junction)Prime core parked; A720 clamped to 2.2GHz · 22–28 tok/s
Stage 4: Emergency Throttle (> 82°C Junction)Heavy thermal governor clamp across all cores · 8–12 tok/s
Remove Insulative Cases

Thick silicone, leather, or rugged polycarbonate phone cases trap radiant heat, causing CPU junction temperatures to reach the 80°C throttle limit 3.5× faster than an unencased phone.

Avoid Concurrent Fast Charging

Fast charging (30W–120W) generates substantial thermal heat inside the battery pack. Combining fast charging with LLM matrix multiplication instantly trips Stage 3/4 throttling.

Enforce 4-Thread Cap

Restricting execution to 4 performance threads limits the total SoC power draw to 4.5W–6W, allowing the phone vapor chamber to stabilize indefinitely at Stage 2 without dropping off the performance cliff.

Context Window KV Cache RAM Sizing Table

The Key-Value (KV) cache stores past token attention states in physical memory. Memory consumption scales strictly linearly with context length. Plan your token budget to prevent Android Low Memory Killer (LMK) terminations:

Model Parameter Tier2k Context (Standard)4k Context8k Context16k ContextSafe Minimum Device RAM
1.5B Parameters (e.g. Qwen 2.5 1.5B)140 MB280 MB560 MB1.12 GB4 GB RAM devices
3B Parameters (e.g. Llama 3.2 3B)250 MB500 MB1.00 GB2.00 GB6 GB – 8 GB RAM devices
7B – 8B Parameters (e.g. Qwen 2.5 7B, Llama 3.1 8B)520 MB1.04 GB2.08 GB4.16 GB12 GB+ RAM devices
14B Parameters (e.g. Qwen 2.5 14B Q4)980 MB1.96 GB3.92 GB7.84 GB16 GB+ Workstations / Flagships

* Note: KV cache figures assume FP16 precision. When using Q8_0 or Q4_0 quantized KV cache (available in Local AI advanced developer settings), memory footprint is reduced by 50% to 75% respectively, allowing higher context limits on 6GB/8GB devices.

Performance, Thermal & Cache FAQs

Why is setting 4 threads faster and cooler than setting 8 threads on Android?+
Modern ARM mobile processors use DynamIQ big.LITTLE architectures consisting of 1 Prime core, 3–4 Performance cores, and 3–4 Efficiency cores. Efficiency cores (Cortex-A510/A520) have half the SIMD vector width and lower clock frequencies. When matrix multiplication workloads are split across 8 threads, fast performance cores finish early and idle at pthread barrier synchronizations waiting for slow efficiency cores. Setting thread count to 4 keeps execution pinned strictly to high-IPC performance cores.
What does memory-mapped I/O (mmap) do in Local AI?+
Without mmap, the app must read the entire 4GB GGUF file from disk into RAM byte-by-byte using sequential fread() calls, taking 10 to 15 seconds. With mmap enabled, the OS kernel maps the file on flash storage directly into the process virtual address space. Clean file pages are streamed dynamically into resident memory via minor page faults on demand, cutting model startup time to under 1.5 seconds.
How does CPU thermal throttling affect token generation speed?+
Smartphones use passive thermal cooling. When sustained LLM matrix computations push the CPU junction temperature above 80°C, the kernel thermal governor steps down clock frequencies (e.g. 3.3 GHz down to 1.8 GHz) or disables the Prime Cortex-X core completely. This causes token generation to drop by 40% to 65% unless mitigated by 4-thread execution, case removal, or cooler ambient airflow.
How much memory does the Key-Value (KV) cache consume at 8k or 16k context?+
KV cache memory scales linearly with sequence length. On a 3B model (like Llama 3.2 3B with Grouped-Query Attention), a 2k context consumes ~250MB, but an 8k context consumes ~1.0GB, and 16k consumes ~2.0GB of RAM purely for attention states. On phones with 6GB or 8GB RAM, setting context above 4k risks triggering the Android Low Memory Killer (LMK).
How much battery does generating 1,000 words actually consume?+
On a Snapdragon 8 Gen 3 phone, generating 1,000 tokens (roughly 750 words) takes approximately 25 seconds of computation and consumes between 0.8% and 1.1% of total battery charge. When the model is idle (waiting for you to read or type), it consumes virtually zero milliwatts.
Does fast internal flash storage (UFS 4.0 vs UFS 2.2) affect token speed?+
Storage speed affects initial model loading and prompt prefill when weights are first paged into RAM. Once weights are resident in LPDDR5X RAM, token generation speed is bound entirely by RAM memory bus bandwidth and CPU vector ALUs, not flash storage speed.
TEST AT MAXIMUM PERFORMANCE

Download Local AI for Android

Equipped with hardware-aware thread allocation, memory-mapped storage, and Smart RAM protection.

Get Early Access ↗