Skip to content

[google_maps_flutter] Add ability to perform Google Maps SDK warmup #9674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Aug 6, 2025

Conversation

filiph
Copy link
Contributor

@filiph filiph commented Jul 25, 2025

The Android Google Maps SDK janks when the first map is shown, completely blocking the app thread. This PR introduces GoogleMapsFlutterAndroid.warmup() which lets Flutter developers do what Android developers do to mitigate this: a fake show of a Google Map that forces the SDK to initialize. This is typically done at app startup so that the jank is less visible than during, say, a page transition.

More info: flutter/flutter#28493 (comment)

This PR also introduces injecting MapsInitializerApi to the GoogleMapsFlutterAndroid constructor, for testing, and adds a basic test for initializeWithRenderer, too.

Fixes flutter/flutter#28493

Pre-Review Checklist

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

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.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2 3

Copy link

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

Choose a reason for hiding this comment

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

Code Review

This PR introduces a warmup method to mitigate the initial jank on Android, along with dependency injection for testing. Adding onResume() to the MapView lifecycle methods in the warmup process would ensure it's as effective as possible.

@filiph filiph changed the title [google_maps_flutter] [WIP] Add ability to perform Google Maps SDK warmup [google_maps_flutter] Add ability to perform Google Maps SDK warmup Jul 28, 2025
@filiph
Copy link
Contributor Author

filiph commented Jul 28, 2025

Hey maintainers, I've finalized this PR and removed the WIP tag. I see that one of the test suites failed with a timeout, but I think maybe that's not my fault.

@reidbaker
Copy link
Contributor

Hey maintainers, I've finalized this PR and removed the WIP tag. I see that one of the test suites failed with a timeout, but I think maybe that's not my fault.

Yeah I dont think that should prevent review.

Copy link
Contributor

@reidbaker reidbaker left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution!

@@ -2,7 +2,7 @@ name: google_maps_flutter_android
description: Android implementation of the google_maps_flutter plugin.
repository: https://github.com/flutter/packages/tree/main/packages/google_maps_flutter/google_maps_flutter_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
version: 2.17.0
version: 2.17.1
Copy link
Contributor

Choose a reason for hiding this comment

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

@stuartmorgan-g should this be a minor version bump not a patch version bump?
I reviewed https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md but didnt see anything more specific than my general understadning of sem-ver.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, since it adds new public API semver requires it to be a minor API bump. (That's not a repo policy, it's basic semver.)

Copy link
Contributor

Choose a reason for hiding this comment

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

@filiph I think this is still blocking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this was already addressed in 8b9878e ? Or at least I see this as addressed both locally and here on github.

filiph and others added 4 commits July 29, 2025 10:09
@@ -2,7 +2,7 @@ name: google_maps_flutter_android
description: Android implementation of the google_maps_flutter plugin.
repository: https://github.com/flutter/packages/tree/main/packages/google_maps_flutter/google_maps_flutter_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
version: 2.17.0
version: 2.17.1
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, since it adds new public API semver requires it to be a minor API bump. (That's not a repo policy, it's basic semver.)

@filiph
Copy link
Contributor Author

filiph commented Aug 1, 2025

Thanks for the feedback. Implemented.

///
/// This gives the developer the option to move that jank to a different
/// part of the map (typically, the app startup, where missed frames
/// aren't going to be noticed).
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove the parenthetical here, per the discussion in the README.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


return switch (initializedRenderer) {
PlatformRendererType.latest => AndroidMapRenderer.latest,
PlatformRendererType.legacy => AndroidMapRenderer.legacy,
};
}

/// Asks the Google Maps SDK to do the thread-blocking work it normally does
Copy link
Contributor

Choose a reason for hiding this comment

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

How about "Attempts to trigger any thread-blocking work the Google Maps SDK normally does when a map is shown for the first time."

It's not actually asking the SDK to do this; that implies some officially supported API intended for this purpose. Instead it's trying to trigger it via reliance on internal implementation details of the SDK that could change at any time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I really like this, thanks for the suggestion! Implemented.

@@ -1,3 +1,7 @@
## 2.18.0

* Adds GoogleMapsFlutterAndroid.warmup().
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: backticks around the code.

Also, this should provide some client-facing context about what this is, rather than someone needing to go read the API docs to understand what this method is for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I came up with

* Adds support for warming up the Google Maps SDK 
  via `GoogleMapsFlutterAndroid.warmup()`.

I try to balance the laconic style of the changelog with giving some context, but I feel I'm botching it?


/// Attempts to trigger any thread-blocking work
/// the Google Maps SDK normally does when a map is shown for the first time.
@async
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I missed this in previous review: why is this marked @async? There's no async step in the Java code, it's all synchronous. Without the @async annotation the Java code would be simpler, without the possibility of accidentally not calling the result.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah! Damn, sorry I missed it. The original code was async but then I found out it wouldn't work so I made it synchronous — and promptly forgot about this being async.

Addressed.

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

LGTM

@stuartmorgan-g stuartmorgan-g added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 6, 2025
@auto-submit auto-submit bot merged commit 091b87d into flutter:main Aug 6, 2025
80 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 7, 2025
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Aug 7, 2025
flutter/packages@f0b2726...6efb759

2025-08-06 [email protected]
[camera_android_camerax] Re-land "Force new Surface for each
SurfaceRequest" (flutter/packages#9760)
2025-08-06 [email protected] [google_maps_flutter] Add
ability to perform Google Maps SDK warmup (flutter/packages#9674)
2025-08-06 [email protected] Roll Flutter from
59fc766 to 9de63a0 (6 revisions) (flutter/packages#9764)
2025-08-06 [email protected] [webview_flutter_wkwebview]
Extended Web View API on iOS to add flexibility when working with local
HTML content (flutter/packages#8787)

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

To file a bug in Flutter:
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
houssemeddinefadhli81 pushed a commit to houssemeddinefadhli81/flutter that referenced this pull request Aug 7, 2025
…r#173414)

flutter/packages@f0b2726...6efb759

2025-08-06 [email protected]
[camera_android_camerax] Re-land "Force new Surface for each
SurfaceRequest" (flutter/packages#9760)
2025-08-06 [email protected] [google_maps_flutter] Add
ability to perform Google Maps SDK warmup (flutter/packages#9674)
2025-08-06 [email protected] Roll Flutter from
59fc766 to 9de63a0 (6 revisions) (flutter/packages#9764)
2025-08-06 [email protected] [webview_flutter_wkwebview]
Extended Web View API on iOS to add flexibility when working with local
HTML content (flutter/packages#8787)

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

To file a bug in Flutter:
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App p: google_maps_flutter platform-android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[google_maps_flutter] App is lagging when initializing Google Maps
3 participants