daily-tech:2026-11-19 現象:模型沒有變大,畫面卻開始卡 / Symptom: The model is unchanged, but frames stall 手機把相機畫面交給端側 AI 模型時,最直覺的做法是先複製到 CPU,再複製到 GPU 或 NPU。資料量一大,模型本身可能沒有變慢,真正增加的是搬運、等待與格式轉換。共享 buffer 可以減少複製,但若忽略同步,畫面可能讀到未完成的資料,或因等待 producer 而出現尾端延遲。 When a phone sends camera frames to an on-device AI model, the obvious path copies pixels through the CPU and then to the GPU or NPU. With larger frames, transport, waiting, and format conversion can dominate even when the model is unchanged. Shared buffers can reduce copies, but missing synchronization can expose incomplete data or create tail latency. Android AI buffer path Camera / CPU producer AHardwareBuffer shared handle DMA-BUF fd import + fence GPU / NPU consumer cache sync + fence + lifetime still matter 圖 1|共享 buffer 減少搬運,但 cache、fence 與生命週期仍需管理。 / Figure 1 | Shared buffers reduce copies, but cache, fences, and lifetime still need explicit management. 機制:HardwareBuffer 是入口,DMA-BUF 是共享路徑 / Mechanism: HardwareBuffer is the Android entry, DMA-BUF i...
daily-tech:2026-11-18 現象:App 沒有崩潰,畫面卻突然停住 / Symptom: The app is alive, but frames suddenly stop Android App 在滑動、開啟相機或載入模型時,可能沒有 Crash,畫面卻短暫停住。很多人先把問題歸咎於 CPU 不夠快,但 ART 的記憶體回收也會讓應用程式執行緒暫停。要找原因,先把配置物件、堆積成長和 GC 暫停分開觀察。 An Android app may not crash, yet briefly freeze while scrolling, opening the camera, or loading a model. CPU speed is an easy suspect, but ART garbage collection can also pause application threads. Separate allocation, heap growth, and GC pauses before changing code or hardware. 機制:ART 如何把垃圾回收放進執行流程 / Mechanism: how ART places GC into execution ART 使用 managed heap 管理 Java 與 Kotlin 物件。程式配置新物件時,堆積會逐步接近成長界線;當回收條件成立,GC 會找出仍被參考的物件,回收不可達空間,並依回收器與階段產生不同程度的工作。背景回收不代表完全沒有停頓:根掃描、執行緒協調與記憶體壓縮仍可能反映在畫面幀時間。 ART manages Java and Kotlin objects in a managed heap. Allocations move the heap toward its growth boundary; when collection is needed, GC identifies reachable objects and reclaims unreachable space. Concurrent work does not mean zero pauses: root scanning, thread coordination, and com...