Skip to content

[android]: prewarms shaders when the context is created - #196069

Merged
auto-submit[bot] merged 9 commits into
flutter:masterfrom
gaaclarke:warm-default-pipelines
Nov 12, 2026
Merged

auto-submit[bot] merged 9 commits into
flutter:masterfrom
gaaclarke:warm-default-pipelines

Conversation

@gaaclarke

@gaaclarke gaaclarke commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

This preemptively starts compiling shaders as soon as the Context is created instead of waiting for the surface to be created. This has been measured to reduce startup time for mokey by 160ms.

One gotcha is that on vulkan the pixel format is compiled into the shaders, getting it wrong is very wasteful. Today we only use r8g8b8a8, but in the future that may change when we support wide gamut. I've added a debug assert to make sure what we warm up is what we use, which i'm pretty sure will be correct.

See the linked issue for more info ( #195920 )

fixes #195920

before

after

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@github-actions github-actions Bot added platform-android Android applications specifically engine flutter/engine related. See also e: labels. e: impeller Impeller rendering backend issues and features requests team-android Owned by Android platform team labels Nov 5, 2026
@gaaclarke
gaaclarke marked this pull request as ready for review November 6, 2026 18:54
@gaaclarke
gaaclarke requested a review from a team as a code owner November 6, 2026 18:54
@gaaclarke
gaaclarke requested review from camsim99 and removed request for a team November 6, 2026 18:54

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a mechanism to warm up default pipelines asynchronously before a rendering surface is created, reducing first-frame compilation latency. It refactors ContentContext to extract pipeline creation into a static CreateDefaultPipelines method and adds WarmDefaultPipelines to trigger this compilation early. On Android, PlatformViewAndroid is updated to warm up these pipelines during context setup and verify that the surface's default color format matches the warmed format. Additionally, unit tests and mocks are added to verify this behavior. Feedback on the changes points out a redundant heap allocation of pipelines_ in the ContentContext constructor initializer list, as it is subsequently overwritten.

Comment on lines +859 to +862
lazy_glyph_atlas_(
std::make_shared<LazyGlyphAtlas>(std::move(typographer_context))),
pipelines_(new Pipelines()),
tessellator_(std::make_shared<Tessellator>(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

In the initializer list, pipelines_ is initialized with new Pipelines(). However, later in the constructor (line 918), pipelines_ is completely overwritten by pipelines_ = std::move(pipelines);. This results in a redundant heap allocation of the Pipelines struct on every construction of ContentContext.

You should remove pipelines_(new Pipelines()), from the initializer list so that it default-initializes to nullptr and avoids the redundant allocation.

Suggested change
lazy_glyph_atlas_(
std::make_shared<LazyGlyphAtlas>(std::move(typographer_context))),
pipelines_(new Pipelines()),
tessellator_(std::make_shared<Tessellator>(
lazy_glyph_atlas_(
std::make_shared<LazyGlyphAtlas>(std::move(typographer_context))),
tessellator_(std::make_shared<Tessellator>(

@walley892

Copy link
Copy Markdown
Contributor

One gotcha is that on vulkan the pixel format is compiled into the shaders, getting it wrong is very wasteful

There are a few ways in which this is wasteful:

  1. We'll (in the worst case) double the size of the shader cache. I'm not sure what the memory footprint of this will be - do we have good metrics here?

  2. I'm less familiar with Vulkan compilation. If we enqueue all of the shaders for compilation with a bad color format default (round 1), then we enqueue them again with the correct default (round 2) - will all the round 2 shaders be stuck waiting for round 1?

@gaaclarke

Copy link
Copy Markdown
Member Author

We'll (in the worst case) double the size of the shader cache. I'm not sure what the memory footprint of this will be - do we have good metrics here?

We have an assert right now to make sure it doesn't happen.

I'm less familiar with Vulkan compilation. If we enqueue all of the shaders for compilation with a bad color format default (round 1), then we enqueue them again with the correct default (round 2) - will all the round 2 shaders be stuck waiting for round 1?

It will perform it on the raster thread, like the opengles compile queue. However, it will never happen this way because of the assert. I'm kicking the can down the road until we do wide gamut.

@walley892 walley892 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm most familiar with the content_context code, and that all looks good to me.

To check my understanding: This is just a splitting of ContentContext creation into explicit Setup -> CreateDefaultPipelines steps. And the ContentContext creator can call CreatePipelines independently before actually creating a ContentContext

If CreatePipelines has been called independently first, the (Make ContentContext -> CreatePipelines) step of ContextCreation will be mostly a no-op because the shaders will already be in the pipeline cache.

Is that correct? I would maybe beef up the description a bit.

This LGTM, but I'm still holding of on approval since I'm not familiar with the Android platform side of things - can we get another approver who has more familiarity there?

@gaaclarke

Copy link
Copy Markdown
Member Author

I'm most familiar with the content_context code, and that all looks good to me.

To check my understanding: This is just a splitting of ContentContext creation into explicit Setup -> CreateDefaultPipelines steps. And the ContentContext creator can call CreatePipelines independently before actually creating a ContentContext

If CreatePipelines has been called independently first, the (Make ContentContext -> CreatePipelines) step of ContextCreation will be mostly a no-op because the shaders will already be in the pipeline cache.

Is that correct? I would maybe beef up the description a bit.

That's correct. I've documented that in the warmup code here: https://github.com/flutter/flutter/pull/196069/changes#diff-9f647a91741f5a3536d4f6656ffe646292f0ec47bc446003def7cb4b30d81118R848

There is more information in the issue that is linked too which is worth checking out.

This LGTM, but I'm still holding of on approval since I'm not familiar with the Android platform side of things - can we get another approver who has more familiarity there?

That code falls squarely on our shoulders to maintain. Go ahead and take your time learning that until you feel comfortable providing a review. The linked issue has some sequence diagrams that should hopefully help. Let me know if you want to video chat.

@gaaclarke
gaaclarke requested a review from walley892 November 10, 2026 00:32
@gaaclarke

Copy link
Copy Markdown
Member Author

(i've inlined the before/after sequence diagrams)

walley892
walley892 previously approved these changes Nov 10, 2026
@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 10, 2026
@auto-submit

auto-submit Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/196069, because - The status or check suite Dashboard Checks has failed. Please fix the issues identified (or deflake) before re-applying this label.

@gaaclarke
gaaclarke requested a review from walley892 November 11, 2026 00:55
@gaaclarke

Copy link
Copy Markdown
Member Author

@walley892 sorry, i had to fix some clang tidys

@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 11, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 11, 2026
@auto-submit

auto-submit Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/196069, because - The status or check suite ci.yaml validation has failed. Please fix the issues identified (or deflake) before re-applying this label.

  • The status or check suite Mac_arm64_verify_binaries has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Tree_analyze has failed. Please fix the issues identified (or deflake) before re-applying this label.

@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 11, 2026
@auto-submit

auto-submit Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/196069, because - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 11, 2026
@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 11, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Nov 11, 2026
Merged via the queue into flutter:master with commit b1ea363 Nov 12, 2026
25 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 12, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Nov 12, 2026
flutter/flutter@b98afb5...9c427b5

2026-11-12 [email protected] Roll Skia from d67d0f22e3ec to 9aa2513a4ac9 (2 revisions) (flutter/flutter#196429)
2026-11-12 [email protected] [flutter_tools] Move CpuArch to flutter_tools_core and define HostPlatform by osName and cpuArch (flutter/flutter#195841)
2026-11-12 [email protected] Roll Skia from 23e7e63789b8 to d67d0f22e3ec (2 revisions) (flutter/flutter#196424)
2026-11-12 [email protected] Uber compactify (flutter/flutter#196392)
2026-11-12 [email protected] Roll Skia from 3d7e335da165 to 23e7e63789b8 (12 revisions) (flutter/flutter#196422)
2026-11-12 [email protected] Roll Dart SDK from 13af329ea4f2 to e5add7a25b32 (1 revision) (flutter/flutter#196413)
2026-11-12 [email protected] Don't terminate the shared EGL display when an engine is disposed (flutter/flutter#194520)
2026-11-11 [email protected] Adds manifest flag to turn on SDFs for Android. (flutter/flutter#196056)
2026-11-11 [email protected] Remove bringup from Linux_pixel_7pro integration_ui_keyboard_inset_jump (flutter/flutter#196334)
2026-11-11 [email protected] Uses system default locale for text rendering when preferred locale isn't supported (flutter/flutter#195997)
2026-11-11 [email protected] [android]: prewarms shaders when the context is created (flutter/flutter#196069)
2026-11-11 [email protected] iOS: Recomposite platform views only if their parameters change (flutter/flutter#196287)
2026-11-11 [email protected] [flutter_tools] Forward encoding in ErrorHandlingFile.readAsStringSync (flutter/flutter#196136)
2026-11-11 [email protected] Roll Skia from b89c24bbab8c to 3d7e335da165 (8 revisions) (flutter/flutter#196390)
2026-11-11 [email protected] Add Flutter Gardener instructions on how to disable a test (flutter/flutter#196312)
2026-11-11 [email protected] [Impeller] Enable malioc analysis for framebuffer_blend shaders (flutter/flutter#196343)
2026-11-11 [email protected] [flutter_tools] Migrate general.shard Android, asset, and build tests off globals (flutter/flutter#196125)
2026-11-11 [email protected] Roll Dart SDK from 8f15c4ca2d41 to 13af329ea4f2 (1 revision) (flutter/flutter#196386)
2026-11-11 [email protected] [Impeller] Do not clamp the local coverage limit to the root render target (flutter/flutter#195860)
2026-11-11 [email protected] [Impeller] Use separate uniform buffers on VMware SVGA3D (flutter/flutter#196022)
2026-11-11 [email protected] [flutter_tools] Introduce AndroidSdkProvider for lazy native_assets SDK lookup (flutter/flutter#196122)
2026-11-11 [email protected] Moves linux to ThinLTO. (flutter/flutter#196314)
2026-11-11 [email protected] [flutter_tools] Migrate bin/fuchsia_tester.dart off globals and runInContext (flutter/flutter#196074)
2026-11-11 [email protected] Changes the tolerances for frame_rate_main_test.dart. (flutter/flutter#196304)
2026-11-11 [email protected] Roll Packages from 08faf64 to 653628e (16 revisions) (flutter/flutter#196381)
2026-11-11 [email protected] Allow SliverCrossAxisGroup children to lay out with zero cross-axis extent instead of asserting (flutter/flutter#191287)
2026-11-11 [email protected] Roll Skia from cc4c54f752ba to b89c24bbab8c (4 revisions) (flutter/flutter#196375)
2026-11-11 [email protected] [Linux] Fix layer offset when compositing with glBlitFramebuffer (flutter/flutter#196189)
2026-11-11 [email protected] [flutter_tools] Inject CrashReportSender into SwiftPM migration (flutter/flutter#196315)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
@andywolff

Copy link
Copy Markdown
Contributor

reason for revert: broke android_hardware_smoke_opengles_instrumented_tests shard, seems to have introduced a deadlock on opengles #196453

@andywolff andywolff added the revert Autorevert PR (with "Reason for revert:" comment) label Nov 12, 2026
@flutteractionsbot

Copy link
Copy Markdown
Contributor

Successfully created revert PR: #196468

@flutteractionsbot flutteractionsbot removed the revert Autorevert PR (with "Reason for revert:" comment) label Nov 12, 2026
gaaclarke added a commit to flutteractionsbot/flutter that referenced this pull request Nov 13, 2026
Mairramer pushed a commit to Mairramer/flutter that referenced this pull request Nov 13, 2026
…ter#196468)

Reverts: [[android]: prewarms shaders when the context is
created](flutter#196069)

Initiated by: @andywolff

Reason for reverting: broke
android_hardware_smoke_opengles_instrumented_tests shard, seems to have
introduced a deadlock on opengles
flutter#196453

Original PR Author: @gaaclarke

Reviewed By: @walley892

The original PR description is provided below:

This preemptively starts compiling shaders as soon as the Context is
created instead of waiting for the surface to be created. This has been
measured to reduce startup time for mokey by 160ms.

One gotcha is that on vulkan the pixel format is compiled into the
shaders, getting it wrong is very wasteful. Today we only use r8g8b8a8,
but in the future that may change when we support wide gamut. I've added
a debug assert to make sure what we warm up is what we use, which i'm
pretty sure will be correct.

See the linked issue for more info (
flutter#195920 )

fixes flutter#195920

### before 

<img
src="https://private-user-images.githubusercontent.com/30870216/696606728-5df99815-84ba-4767-8652-f62b1868deab.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3OTQyNzExNTAsIm5iZiI6MTc5NDI3MDg1MCwicGF0aCI6Ii8zMDg3MDIxNi82OTY2MDY3MjgtNWRmOTk4MTUtODRiYS00NzY3LTg2NTItZjYyYjE4NjhkZWFiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjExMTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYxMTEwVDAwMzQxMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTEwOTU4ZmY2ODY4M2U2MGM2NWYwODdmMTVmNzVkMjBlZmE2NGVhOWViYmNjNDE1NjE0NzE1ZjdmOTEyOWNhZGMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JnJlc3BvbnNlLWNvbnRlbnQtdHlwZT1pbWFnZSUyRnBuZyJ9.Pby0uXVIz5VeI6D2yIjY7esMaH_YFrXLyxvRm6C2UgY">

### after

<img
src="https://private-user-images.githubusercontent.com/30870216/696783031-e835a389-c85a-43c4-8b82-2624073a351e.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3OTQyNzExNTEsIm5iZiI6MTc5NDI3MDg1MSwicGF0aCI6Ii8zMDg3MDIxNi82OTY3ODMwMzEtZTgzNWEzODktYzg1YS00M2M0LThiODItMjYyNDA3M2EzNTFlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjExMTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYxMTEwVDAwMzQxMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWU2M2FmNWFmOTkzZGFjOTM3Mzg1MjU5NzEzNmViZmZmNTBiYWM4MWYyOTI0ZjU5NGZhNTFiZWZhNzU1YjRjNzYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JnJlc3BvbnNlLWNvbnRlbnQtdHlwZT1pbWFnZSUyRnBuZyJ9.OYVGbEZQScWwQ4R1z8vA_2HqSbfvIH5W_2qRE4w4GuA">

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant in-code documentation (doc comments with
`///`).
- [x] If this PR introduces a new feature or capability, I created and
linked a website documentation issue or PR in [flutter/website] (or
verified none is needed).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

If this change needs to override an active code freeze, provide a
comment explaining why. The code freeze workflow can be overridden by
code reviewers. See pinned issues for any active code freezes with
guidance.

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[AI contribution guidelines]:
https://github.com/flutter/flutter/blob/main/CONTRIBUTING.ai.md
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[flutter/website]: https://github.com/flutter/website
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md

Co-authored-by: Aaron Clarke <[email protected]>
gaaclarke added a commit to gaaclarke/flutter that referenced this pull request Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD e: impeller Impeller rendering backend issues and features requests engine flutter/engine related. See also e: labels. platform-android Android applications specifically team-android Owned by Android platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Eagerly initializeAiksContext on the raster thread during Shell::Create instead of waiting until SurfaceView.surfaceCreated

4 participants