Repository navigation
[android]: prewarms shaders when the context is created - #196069
Conversation
There was a problem hiding this comment.
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.
| lazy_glyph_atlas_( | ||
| std::make_shared<LazyGlyphAtlas>(std::move(typographer_context))), | ||
| pipelines_(new Pipelines()), | ||
| tessellator_(std::make_shared<Tessellator>( |
There was a problem hiding this comment.
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.
| 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>( | |
There are a few ways in which this is wasteful:
|
We have an assert right now to make sure it doesn't happen.
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
left a comment
There was a problem hiding this comment.
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?
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.
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. |
|
(i've inlined the before/after sequence diagrams) |
|
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. |
|
@walley892 sorry, i had to fix some clang tidys |
|
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.
|
|
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. |
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
|
reason for revert: broke android_hardware_smoke_opengles_instrumented_tests shard, seems to have introduced a deadlock on opengles #196453 |
|
Successfully created revert PR: #196468 |
…ter#196069)" This reverts commit b1ea363.
…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]>
…tter#196069)" This reverts commit 8b6980b.
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-assistbot 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.