Skip to content

RFC 410.0000: Android Dynamic Performance Framework (ADPF) Integration for Flutter - #45

Merged
gmackall merged 6 commits into
flutter:mainfrom
gmackall:adpf-rfc
Nov 19, 2026
Merged

gmackall merged 6 commits into
flutter:mainfrom
gmackall:adpf-rfc

Conversation

@gmackall

@gmackall gmackall commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

A proposal to adopt Android's APerformanceHintManager NDK API (Android 15+ / API 35+) into the Android engine to report per-frame UI and raster thread work durations and post-idle workload resets (Android 16+ / API 36+) to the OS scheduler.

Tracking issue: flutter/flutter#195992 (related: flutter/flutter#114835)

Pre-launch Checklist

  • I read RFC 000.0001: Taxonomy and followed the file and path naming and metadata standards.
  • I read RFC 000.0002: Process and confirmed this proposal meets the threshold for a full RFC.
  • I read and agree to the Code of Conduct.
  • I signed the CLA.
  • I have linked an issue from flutter/flutter with the label design doc.
  • All existing and new tests are passing.
  • I have enabled "Allow edits from maintainers" on this PR so the bot can automatically assign an RFC number (or I will run dart run bin/assign_rfc_number.dart locally when instructed).

The adpf-pure-dual branch has had master merged in, so comparing it
against the pinned base commit showed hundreds of unrelated commits.
Compare against master instead. Also link dev/benchmarks as a tree.

### Interaction with the Android Embedder API migration

Today, Flutter already places Android-specific OS scheduler hints in `flutter/fml/` behind a platform-agnostic interface that is a no-op on other OSes (see [`fml/cpu_affinity.h`](https://github.com/flutter/flutter/blob/4c15b121486e83f0faecee2edb4e86bd41055e19/engine/src/flutter/fml/cpu_affinity.h) and [`fml/platform/android/cpu_affinity.cc`](https://github.com/flutter/flutter/blob/4c15b121486e83f0faecee2edb4e86bd41055e19/engine/src/flutter/fml/platform/android/cpu_affinity.cc)). When `AndroidShellHolder` migrates to the C Embedder API ([flutter/rfc#24](https://github.com/flutter/rfc/pull/24)), we can follow that same pattern so **no `embedder.h` API changes are required**:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable to me. We can always add the embedder api later if we really want to push these platform specifics out of the engine. But since they are there now, I'd just keep the same pattern. WDYT @loic-sharma

@mboetger
mboetger requested a review from gaaclarke November 11, 2026 21:58
4. Forwards both hint managers through `PlatformViewAndroid::CreateVSyncWaiter` into `VsyncWaiterAndroid` so [`VsyncWaiterAndroid::AwaitVSync`](https://github.com/flutter/flutter/blob/4c15b121486e83f0faecee2edb4e86bd41055e19/engine/src/flutter/shell/platform/android/vsync_waiter_android.cc#L29-L61) can call **[`APerformanceHint_notifyWorkloadReset`](https://developer.android.com/ndk/reference/group/a-performance-hint#aperformancehint_notifyworkloadreset) on Android 16+ (API 36+) when a frame is requested more than 100 ms after the session's last notification** (capped at 3 resets between actual work reports), telling the PowerHAL that the workload history from before the idle period is stale (mirroring Android HWUI's [`HintSessionWrapper::sendLoadResetHint`](https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/libs/hwui/renderthread/HintSessionWrapper.cpp)).
5. **Closes both [`APerformanceHintSession`](https://developer.android.com/ndk/reference/group/a-performance-hint#aperformancehintsession) instances** (via [`APerformanceHint_closeSession`](https://developer.android.com/ndk/reference/group/a-performance-hint#aperformancehint_closesession)) and frees their [`AWorkDuration`](https://developer.android.com/ndk/reference/group/a-performance-hint#aworkduration) structs (via [`AWorkDuration_release`](https://developer.android.com/ndk/reference/group/a-performance-hint#aworkduration_release)) in [`AndroidShellHolder::~AndroidShellHolder`](https://github.com/flutter/flutter/blob/4c15b121486e83f0faecee2edb4e86bd41055e19/engine/src/flutter/shell/platform/android/android_shell_holder.cc#L209-L212) before `thread_host_.reset()` joins and destroys `ThreadHost`'s OS threads, ensuring the sessions are closed while their registered thread IDs are still alive.

### Note on merged threads for HC

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this has come up a few times, I just want to go on record saying we should remove this. I may put up a few PRs to just remove this since we don't want it codified in the Embedder API (for #24)

@gaaclarke gaaclarke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mentioned in the issue that my 2 concerns are:

  1. Opportunity cost and skepticism this is higher priority
  2. Concerns about maintenance on a feature that only affects 10% of devices

If you want to convince me otherwise I think the things you could add to your doc are:

  1. What problem are you trying to solve? I think if the problem is "I want to make 10% of the fastest devices 10% faster" I don't think that's a very compelling proposition.
  2. Adding a section on how we will test and maintain this would be helpful. For example, do we have devicelab devices that can use this and run benchmarks on it?

I think my take right now is that this is something we do 5 years from now when the landscape is different and instead focus on raising the floor for our worst devices.

@gmackall

Copy link
Copy Markdown
Member Author
  1. What problem are you trying to solve? I think if the problem is "I want to make 10% of the fastest devices 10% faster" I don't think that's a very compelling proposition.

I think I strongly disagree that making 10% of all android devices 20-40% faster, and in particular having that effect kick in when the devices would jank (miss frame deadlines) is not impactful. I'd be surprised if we have many examples of work that achieved a similar outcome/effort ratio.

  1. Adding a section on how we will test and maintain this would be helpful. For example, do we have devicelab devices that can use this and run benchmarks on it?

Sure I can add this. I want to stress that the feature is "take metrics we already measure, plumb them to android, and let android handle it". I don't agree that maintenance will be high here.

@gaaclarke

Copy link
Copy Markdown
Member
  1. What problem are you trying to solve? I think if the problem is "I want to make 10% of the fastest devices 10% faster" I don't think that's a very compelling proposition.

I think I strongly disagree that making 10% of all android devices 20-40% faster, and in particular having that effect kick in when the devices would jank (miss frame deadlines) is not impactful. I'd be surprised if we have many examples of work that achieved a similar outcome/effort ratio.

Just to be clear, I wasn't asking that question to be answered in the comments. I was asking for it to be put in the doc, "what problem are you attempting to solve?" =)

@jmagman

jmagman commented Nov 12, 2026

Copy link
Copy Markdown
Member

I think if the problem is "I want to make 10% of the fastest devices 10% faster" I don't think that's a very compelling proposition.

I think those numbers are pretty compelling, like 10s of millions of phones/users. To put that in perspective, in the past we have pushed back on dropping older versions of SDKs when usage was even ~2%, even when there's some maintenance burden trade off. This particular rfc is proposing something that seems to have very little maintenance burden for a large performance improvement on a large number (10% seems large! certainly large in absolute numbers) of devices.

Native Android views already use this under the hood, but Flutter currently does not.

I find this argument compelling as well. Flutter apps could add a small amount of plumbing and the scheduling will behave more like vanilla Android apps, in exchange for some plumbing and very little downside.

@mboetger

Copy link
Copy Markdown

2. Concerns about maintenance on a feature that only affects 10% of devices

@gaaclarke - I'm curious what exactly would constitute this maintenance burden. Since this is plumbing data that is already collected via the engine, isn't the maintenance burden already present?

@gaaclarke

Copy link
Copy Markdown
Member

@gaaclarke - I'm curious what exactly would constitute this maintenance burden. Since this is plumbing data that is already collected via the engine, isn't the maintenance burden already present?

Hey @mboetger, any feature that only affects 10% of devices creates a burden. In automated testing we need to make sure it's represented (I mention this above). For people working on issues they have to make sure they have devices that can support it. When responding to issues from customers it's another variable that has to be tested and is easy to overlook when it's surface area is so small.

For example, imagine this scenario:
day 1 -- Reporter: "Issue: the performance for this sucks on impeller, heres the reproduction."
day 7 -- Engineer: "I've run it, and it runs fine for me, try giving me a profile."
day 8 -- Reporter: "Here you go."
day 8 -- Engineer: "That's weird, what device are you using?"
day 8 -- Reporter: "Some android phone that's hard to buy in America".
day 9 -- Engineer: "I'll order one from dubious origin on ebay."
day 39 -- Engineer: "I got it, turns out your phone didn't support Android Dynamic Performance Framework, I forgot about that esoteric thing that not every phone supports."

People have a hard time estimating how long something will take to make, but they are really bad at estimating the lifetime maintenance cost for a thing. That's why I think it's important we consider what we are hoping to achieve. Considering the scenario above making 10% of new Android phones 3x faster may not even be worth it. The android ecosystem is already super fragmented as it is.

@jtmcdole

Copy link
Copy Markdown
Member

[@gaaclarke](https://github.com/gaaclarke) - I'm curious what exactly would constitute this maintenance burden. Since this is plumbing data that is already collected via the engine, isn't the maintenance burden already present?

To be super crisp here; I think Aaron is asking that we document in the rfc how we plan to have this feature/plumbing tested and continued working, not that this will fall on anyone's shoulders later. We're not saying dubious phones sold or not sold in America exist or not, just that we have experience in the past with "these APIs work for Version X" not working on X when the manufacture updates the OS vs launches with it.

@mboetger

Copy link
Copy Markdown

The android ecosystem is already super fragmented as it is.

@gaaclarke - I agree. And thank you for outlining your concern. The truth of the matter is today, chip manufactures all have their own scheduling and performance algorithms - so the situation described could easily end in "oh, company X has a wonky scheduler". To me, the cost of having to deal with the fragmentation - the scenario you describe - already exists. ADPF is at least trying to unify the ecosystem behind a standardize way of doing performance hints. And ideally 10% today it the lowest it will ever be as more manufacturers adopt. It's hard to accept that this change "may not even be worth it" because of fragmentation.

@gmackall

gmackall commented Nov 14, 2026 •

Copy link
Copy Markdown
Member Author

I will update the doc to make this clearer, but at a high level I view not adopting to be more risky than adopting.

Stock Android apps benefit from ADPF out of the box due to it being adopted already in HWUI, so this is a 10% that represents a material gap in performance between Flutter and stock Android - i.e. on that 10%, Flutter on Android will look worse in comparison to pure Android (simply due to bad OS scheduling decisions).

This 10% is currently growing as api level usage generally creeps forward, and also is decently likely to grow from further OEM adoption (of course, there is uncertainty here), and as it does so that performance gap between Flutter on Android and pure Android will continue to grow.

@gmackall

Copy link
Copy Markdown
Member Author

Updated:

  1. Added a problem statement (basically, that ADPF is creating a performance gap between native Android and Flutter on Android because of HWUI adoption).
  2. Added a suggestion that we gate this behind an on-by-default manifest feature flag and a runtime check that HWUI uses ADPF on the device (at least for initial adoption).
  3. Added testing details, but clarified that I think testing that it actually makes devices faster is out of scope. We don't do this for our CPU affinity configuration, for example, which imo is riskier.
  4. Clarified that I view maintenance as low, and gave reasons.
  5. Also updated the estimate to around ~30% of Android devices impacted — it turns out Samsung does respect it, just to a lesser degree (added a short note in Benchmark Results).
  6. Updated the Proposed Change section to adopt @jtmcdole's formatting suggestion.

@gaaclarke gaaclarke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks gray for incorporating the feedback, 30% is sounding much better and it's a fair point that we aren't on equal footing with android proper unless we take advantage of it.

Just one question on testing.

@gaaclarke gaaclarke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks gray!

gmackall added a commit to gmackall/flutter that referenced this pull request Nov 19, 2026
…ance mode

Add enableFixedPerformanceMode (defaulting to true) to PerfTest, createComplexLayoutScrollPerfTest, and NewGalleryPerfTest so specific Devicelab benchmarks can explicitly disable Android fixed-performance mode and measure performance under the normal OS CPU governor.

Add two side-by-side Linux_pixel_7pro Impeller benchmarks in bringup (suffixed with _noisy because CPU clocks are unpinned) so they can bake and establish long-term baselines ahead of landing Android ADPF integration (RFC 410.0000: flutter/rfc#45):
- complex_layout_scroll_perf_impeller_no_fixed_perf__timeline_summary_noisy
- new_gallery_impeller_no_fixed_perf__transition_perf_noisy
@gmackall gmackall added rfc-ready RFC is ready for review. rfc-assigned AAA.NNN number assigned by the `rfc-assigned` action status: accepted assign-rfc-number Triggers workflow to assign a number to the RFC. labels Nov 19, 2026
@github-actions github-actions Bot removed the assign-rfc-number Triggers workflow to assign a number to the RFC. label Nov 19, 2026
@github-actions

Copy link
Copy Markdown

Assigned RFC 410.0001.

@gmackall
gmackall added this pull request to the merge queue Nov 19, 2026
Merged via the queue into flutter:main with commit 3b439f0 Nov 19, 2026
14 checks passed
andywolff pushed a commit to andywolff/flutter that referenced this pull request Nov 20, 2026
…lutter#197010)

- Add enableFixedPerformanceMode (defaulting to true) to PerfTest,
createComplexLayoutScrollPerfTest, and NewGalleryPerfTest so specific
Devicelab benchmarks can explicitly disable Android fixed-performance
mode and measure performance under the normal OS CPU governor.

- Add two side-by-side Linux_pixel_7pro Impeller benchmarks in bringup
so they can bake and establish baselines ahead of landing Android ADPF
integration (RFC 410.0000):
`complex_layout_scroll_perf_impeller_no_fixed_perf__timeline_summary`
`new_gallery_impeller_no_fixed_perf__transition_perf`

Part of flutter/rfc#45, landing these first so
they have time to bake
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rfc-assigned AAA.NNN number assigned by the `rfc-assigned` action rfc-ready RFC is ready for review. status: accepted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants