[go: nahoru, domu]

Skip to content
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

Potentially overly slow initial map composition caused by exhaustively setting *all* possible map configuration options #499

Open
bubenheimer opened this issue Jan 4, 2024 · 2 comments
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@bubenheimer
Copy link
Contributor
bubenheimer commented Jan 4, 2024

android-maps-compose 4.3.0

I see an avoidable performance hit in the code for the initial GoogleMap() subcomposition run: the code essentially configures all possible Map configuration options in an exhaustive manner, rather than only the ones that the API consumer cares about.

This includes CameraPositionState, LocationSource, all 9 properties in MapProperties, GoogleMap padding, and all 10 properties in MapUISettings. At least 22 GoogleMap class function calls upon initial composition, many of which may never actually need to be explicitly set.

Another part of the problem is that the MapView is already being rendered while all these options are set, exhaustively reconfiguring the map while it is being displayed.

All this would not be much of a problem if all the GoogleMap class function calls were guaranteed to execute swiftly. I suspect that this is not the case for all of them, e.g. due to synchronization/locking/blocking and inter-process calls.

Just to be clear: this is a potential architectural and performance problem I see in the code, not something I have actually experienced or tested.

@bubenheimer bubenheimer added triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Jan 4, 2024
@bubenheimer
Copy link
Contributor Author

This could potentially be addressed by discontinuing reliance on large preconfigured configuration objects to be passed into the GoogleMap() composable. Instead, configuration lambdas/blocks could be used, e.g.:

val propertiesConfig: MapPropertiesScope.() -> Unit = {
    // API consumer might care only about setting a specific map type
    this.mapType = TERRAIN
}

GoogleMap(
    mapPropertiesConfig = propertiesConfig
) {}

These configuration lambdas can be readily executed and observed for changes during composition.

@kikoso kikoso added priority: p3 Desirable enhancement or fix. May not be included in next release. and removed triage me I really want to be triaged. labels Jan 4, 2024
@bubenheimer
Copy link
Contributor Author
bubenheimer commented Jan 5, 2024

In fact, to do this cleanly, it may be necessary to introduce MapConfigurationState that encapsulates all mentioned configuration options, including camera, location source, inside padding. If a user provides a new MapConfigurationState object then the GoogleMap & MapView would need to be recreated, unless there is a reliable way to reset the map configuration to defaults.

The reason for needing this kind of thing is to keep the Compose API properly declarative. The 2 possible properly declarative approaches I see for this are MapConfigurationState or exhaustively setting all options.

Alternatively the Map could also be configured from inside the subcomposition/content block via side effects. The inherent constraint of this approach is performance: initial composition of the potentially complex subcomposition needs to be complete before configuration actions can be performed. Arguably, initial map loading should already be happening in parallel during this time. So I think the subcomposition needs to stay reserved for only configuring the map contents, not configuring the map itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

2 participants