android-maps-compose icon indicating copy to clipboard operation
android-maps-compose copied to clipboard

Performance penalty throughout API from LatLng usages

Open bubenheimer opened this issue 3 years ago • 5 comments

android-maps-compose 2.2.1 compose 1.2.0-rc01

The android-maps-compose API imposes a performance penalty throughout by leveraging the Maps SDK LatLng type, which the compiler is currently unable to infer as stable. (Observed via compose compiler metrics: https://github.com/androidx/androidx/blob/androidx-main/compose/compiler/design/compiler-metrics.md)

I see 2 potential solutions:

  1. Replace LatLng with an equivalent stable type throughout maps-compose API.
  2. Work with compose compiler team to treat LatLng as stable.

I'd consider the second solution preferable.

Code example

@Composable
fun MyComposable(latLng: LatLng) {}

In this example the Compose compiler deems latLng unstable, rendering the composable function non-skippable.

bubenheimer avatar Jun 21 '22 16:06 bubenheimer

The compiler is not able to infer the stability on LatLng as it is an external module. The solutions you propose are indeed the ways to resolve this and I agree that (2) is the right approach. For (1), I'm hesitant introducing a wrapper class as this issue should be addressed at the compiler level. Not much we can do on the maps-compose side to address this, but I will definitely raise this to the compiler team. Thanks for reporting!

arriolac avatar Jun 27 '22 23:06 arriolac

Hi! We ran into this too. Do we have any update on this issue?

YingChen0605 avatar Nov 02 '23 18:11 YingChen0605

Quick update on the compiler side of things:

Compose 1.5.4 compiler released an experimental feature called strong skipping. This will allow composables with unstable parameters to be skipped which should improve performance. Since it is still experimental, I do recommend testing this first to see if you get any runtime performance gains.

arriolac avatar Nov 17 '23 21:11 arriolac

How about "Allow configuring stability via a config file?", also released in 1.5.4. Sounds more ready to use, wouldn't it address this issue as well? https://android-review.googlesource.com/c/platform/frameworks/support/+/2668595

bubenheimer avatar Nov 17 '23 22:11 bubenheimer

Yes, that should address the issue as well (a combination of the two should be tested). It'd be great if maps compose can ship with the necessary stability config file.

arriolac avatar Nov 17 '23 22:11 arriolac

:tada: This issue has been resolved in version 4.3.4 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

googlemaps-bot avatar Apr 16 '24 16:04 googlemaps-bot