dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.2k stars 1.57k forks source link

Dart profiler thread can occupy fast core when running on Android. #53748

Open jonahwilliams opened 1 year ago

jonahwilliams commented 1 year ago

Running a debug/profile mode Flutter application can result in different performance characteristcs than release mode if the device is under any sort of strain. One particular issue on Android is that the Dart Profiler thread is running with very high priority and can occupy one of two fast cores on a Pixel 6.

Perfetto Link: https://ui.perfetto.dev/#!/?s=59bd3e3c6faba4cf102d9b9e09fe24074a78f0103a13c00c62de4ead405d135f

image

The Flutter engine already has mechanisms to set the thread priority and affinity on Android/Linux devices. This is a request for an API (some sort of callback?) the flutter engine can use to adjust the properties of this profiler thread(s).

a-siva commented 1 year ago

@jonahwilliams The VM has a flag worker_thread_priority which sets the thread priority of all threads started by the VM, would this be sufficient?

jonahwilliams commented 1 year ago

Priority is insufficent, we also need to adjust CPU affinity specifically for android due to the heterogeneous clock speeds.

a-siva commented 1 year ago

Priority is insufficent, we also need to adjust CPU affinity specifically for android due to the heterogeneous clock speeds.

another flag similar to thread priority maybe called worker_cpu_affinity which would set the CPU affinity for all threads started by the VM would be sufficient ?

jonahwilliams commented 1 year ago

If it accepted something like a cpu_set_t that might work. i'd need to check when we initialize the VM, we should make sure that we can determine the correct affinity before we need to set that flag.

a-siva commented 9 months ago

@jonahwilliams did you get a chance to check if cpu_set_t would work ?

jonahwilliams commented 9 months ago

Sorry for not getting back to this. We should be able to correctly determine the affinity from almost anywhere, however the cpu_set_t structures are opaque/platform-dependent so I don't think they could be configured via CLI flag.