mapbox / mapbox/mapbox-maps-android
mapboxMap.pixelsForCoordinate() method execute slower than v9
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 578
- Forks
- 161
- PR merge metrics
- No merged PRs in 30d
Description
## Environment
```groovy
implementation 'com.mapbox.maps:android:10.1.0'
// implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:9.6.2'
```
## Expected behavior
The method of converting longitude and latitude into screen coordinates in V10 takes twice as much time as in V9.
Can you optimize the pixelsforcoordinate () method to achieve V9 execution efficiency.
When there are hundreds of thousands of points to calculate, the cost of this method is unacceptable.
## Observed behavior and steps to reproduce
v10:
```kotlin
val mapboxMap = mapView.getMapboxMap()
val count = 1000000
val points = ArrayList()
for (i in 1..count) {
points.add(Point.fromLngLat(110.0, 40.0))
}
var ts = System.currentTimeMillis()
mapboxMap.pixelsForCoordinates(points)
Log.e("info", String.format("-->v10 mapboxMap.pixelsForCoordinates: %.4f s", (System.currentTimeMillis() - ts) / 1000f))
ts = System.currentTimeMillis()
for (pt in points) {
mapboxMap.pixelForCoordinate(pt)
}
Log.e("info", String.format("-->v10 mapboxMap.pixelsForCoordinate: %.4f s", (System.currentTimeMillis() - ts) / 1000f))
```
v9:
```kotlin
mapView.getMapAsync { mapboxMap ->
val projection = mapboxMap.projection
val count = 1000000
val points = ArrayList()
for (i in 1..count) {
points.add(LatLng(40.0, 110.0))
}
// pixelsForCoordinates
var ts = System.currentTimeMillis()
val inputArray = DoubleArray(points.size * 2)
val outputArray = DoubleArray(points.size * 2)
for (i in points.indices) {
val pt = points[i]
inputArray[i * 2] = pt.latitude
inputArray[i * 2 + 1] = pt.longitude
}
projection.toScreenLocations(inputArray, outputArray)
Log.e("info", String.format("-->v9 projection.toScreenLocations: %.4f s", (System.currentTimeMillis() - ts) / 1000f))
// pixelForCoordinate
ts = System.currentTimeMillis()
for (pt in points) {
projection.toScreenLocation(pt)
}
Log.e("info", String.format("-->v9 projection.toScreenLocation: %.4f s", (System.currentTimeMillis() - ts) / 1000f))
}
```
log:
```
2021-12-16 13:36:18.035 15480-15480/com.ixlab.mapbox.wemap E/info: -->v9 projection.toScreenLocations: 0.8410 s
2021-12-16 13:36:18.732 15480-15480/com.ixlab.mapbox.wemap E/info: -->v9 projection.toScreenLocation: 0.6970 s
2021-12-16 13:37:17.693 16385-16385/com.ixlab.mapbox.wemap E/info: -->v10 mapboxMap.pixelsForCoordinates: 1.4400 s
2021-12-16 13:37:19.263 16385-16385/com.ixlab.mapbox.wemap E/info: -->v10 mapboxMap.pixelsForCoordinate: 1.5690 s
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with MapboxMap.pixelsForCoordinates and pixelForCoordinate, then run the issue's Kotlin benchmark comparing the v10 methods with the v9 projection methods over 1,000,000 points. Done means the v10 conversions achieve execution efficiency comparable to the reported v9 timings without changing their results.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100