One Missed Latch Can Permanently Double Flutter's Raster Latency on Android
One missed latch can permanently double Raster latency on Android's KHR swapchain path, and the usual CPU/GPU profiling shows no cause because per-frame work stays flat. Flipping on `EnableHcpp` to use the AHB swapchain keeps Raster at 2.4–2.7 ms, so Flutter apps with stutter after rotation have a clear path out.
On a Galaxy A16 running Android 17 with Flutter 3.50.1 and Impeller Vulkan, rotating the screen a few times pushes Raster p95 from ~2.7 ms to 5.0–7.2 ms, and the penalty sticks for as long as the swapchain goes unrecreated. The Raster thread's per-frame CPU time stays at 2.5–2.7 ms, so the extra latency is pure waiting, not extra work. GPU completion latency climbs from 3–7 ms to 10.9–11.0 ms, and SurfaceFlinger's time-weighted queued-buffer reading moves from ~3.3 to ~4.9.
The cause is a missed latch. In the Vulkan KHR swapchain path, when a frame misses the latch window, that buffer joins a queue. Even after the app resumes producing one buffer per vsync and SurfaceFlinger consumes one per vsync, the queue depth stays at N+1 forever because production and consumption rates are exactly matched. The swapchain's finite image count then forces Raster to wait for fences and available images, stretching its end-to-end latency. `CreateSwapchainKHR` on rotation takes 17–44 ms and can itself miss a latch, so rotation sometimes fixes the state and sometimes creates it; even first startup can land in the backlog.
The workaround is to switch away from KHR. Adding the `io.flutter.embedding.android.EnableHcpp` meta-data to true makes Flutter use the AHB/SurfaceControl swapchain. On the same device, after 11 consecutive rotations, Raster p95 stayed at 2.4–2.7 ms. The KHR path lacks any frame pacing to drain the extra buffer, which is why the backlog becomes permanent.
A single missed latch flips the swapchain queue from N to N+1, and because production and consumption both return to one per vsync, the extra buffer never drains.
The KHR swapchain design lacks a mechanism to shed the extra buffer once the backlog forms; the AHB/SurfaceControl path either paces differently or manages buffer count more aggressively.
Because the issue can also appear on first start, it's not a rotation-specific edge case; it's a buffer-management gap that rotation merely tends to trigger.