跪拜 Guibai
← All articles
Frontend · Android · Flutter

Flutter's CPU Affinity Rollercoaster: Raster Thread Fix Rolled Back After 2x Regression, ADPF RFC Puts OS in Charge

By 恋猫de小郭 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Static CPU affinity keeps trading one device's jank for another's benchmark regression, so Flutter's render-thread placement remains a moving target on modern Android chips. A scheduler-aware approach like ADPF already shows 36–44% raster-time improvements in prototypes, but the remaining light-load regressions mean the framework still has to balance benchmark health against real-world device diversity.

Summary

Flutter keeps running into the same wall: its UI/Raster threads are short and latency-sensitive, but static CPU affinity choices keep misfiring across device architectures. On Snapdragon 8 Elite, restricting the Raster thread to two Prime Cores (4.61 GHz) could be slower than using the six Performance Cores (3.63 GHz) because of thread wake-up costs and frequency ramp-up delays. When Flutter widened the core pool in PR #195071, real devices got faster, but the official `fading_child_animation_perf` benchmark regressed by 2x in `average_frame_rasterizer_time_millis`, forcing a rollback.

This is the fourth round of affinity fixes since 2023. Each fix solved one device class and broke another: first restricting to performance cores to avoid slow cores, then expanding to avoid core crowding on Pixel 8, then fixing misclassification on Oryon's no-little-core design, now rolling back after benchmark regressions. A new RFC (#45) proposes dropping static core selection entirely and using Android's ADPF (Adaptive Performance APIs) to tell the OS which threads matter, the frame deadline, and how long the previous frame took. Prototype benchmarks on Pixel 8 and Pixel 9 show raster averages improving 36–44% in complex-layout and tiles scrolling, though light-load scenes on Pixel 8 and Lenovo Tab regress and Hybrid Composition still has thread-merging quirks.

Takeaways
— On Snapdragon 8 Elite, restricting the Raster thread to two Prime Cores (4.61 GHz) could be slower than letting it run on the six Performance Cores (3.63 GHz) because of wake-up costs and the delay in frequency ramp-up.
— After merging PR #195071, the official `fading_child_animation_perf` benchmark's `average_frame_rasterizer_time_millis` regressed by 2x, leading to a rollback.
— Flutter's CPU affinity fixes have cycled since 2023: first restricting to performance cores, then expanding to avoid over-crowding, then fixing misclassification on no-little-core Oryon, and now rolling back due to regressions.
— The proposed ADPF-based RFC (#45) would let the OS handle thread scheduling, with Flutter only reporting frame deadlines, thread roles, actual frame duration, and idle recovery state.
— Prototype ADPF benchmarks on Pixel 8 and Pixel 9 cut raster averages by 36–44% in complex-layout and tiles scrolling scenarios, but some light-load scenes on Pixel 8 and Lenovo Tab regressed, and Hybrid Composition still has thread-merging issues.
Conclusions

Static CPU affinity is a fragile heuristic: every Flutter fix addresses the scheduler behavior of one chip generation, only to misfire on another, because it ignores frequency ramping, cluster occupancy, and power policy.

The 2x official benchmark regression outweighed the real-world gains on Snapdragon 8 Elite, revealing that Flutter's tuning is paced by its own automated metrics rather than by device-pattern-driven analysis.

Delegating scheduling to Android via ADPF is a structural shift: instead of telling Flutter which cores are 'fast', the framework communicates frame deadlines and workload characteristics to a scheduler that already juggles power, thermal, and other threads, which is a more sustainable model even if the prototype still has edge cases.

Concepts & terms
CPU affinity
A Linux/Android mechanism that constrains a thread to a subset of cores, letting developers steer latency-sensitive work away from slow cores or avoid cache thrashing, at the cost of ignoring system-wide scheduling dynamics.
ADPF (Android Dynamic Performance Framework)
A set of Android APIs that let apps report frame deadlines, thermal state, and workload hints to the system so the CPU scheduler can make frequency, core placement, and power trade-offs dynamically rather than relying on static device parameters.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗