mapbox-maps-android
mapbox-maps-android copied to clipboard
mapboxMap.pixelsForCoordinate() method execute slower than v9
Environment
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:
val mapboxMap = mapView.getMapboxMap()
val count = 1000000
val points = ArrayList<Point>()
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:
mapView.getMapAsync { mapboxMap ->
val projection = mapboxMap.projection
val count = 1000000
val points = ArrayList<LatLng>()
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
@wingkingbobo are you using terrain in v10?
@galinelle I didn't use terrain, but I added a sky layer.
{
"id": "layer-sky",
"type": "sky",
"sky-atmosphere-sun": [-10.0, 85.2],
"sky-type": "atmosphere"
}
I removed the sky layer, but it has no effect on the efficiency of converting longitude and latitude to screen coordinates.
@wingkingbobo, do you experience the same slow execution on v10.2.0?
@ZiZasaurus It seems that there is no difference in the execution speed of the three versions.
------------------------ v10.0.0 ---------------------
2022-01-05 09:29:30.641 3191-3191/com.ixlab.mapbox.wemap E/info: -->v10 mapboxMap.pixelsForCoordinates: 1.5770 s
2022-01-05 09:29:32.137 3191-3191/com.ixlab.mapbox.wemap E/info: -->v10 mapboxMap.pixelsForCoordinate: 1.4960 s
2022-01-05 09:31:00.926 4789-4789/com.ixlab.mapbox.wemap E/info: -->v10 mapboxMap.pixelsForCoordinates: 1.5370 s
2022-01-05 09:31:02.367 4789-4789/com.ixlab.mapbox.wemap E/info: -->v10 mapboxMap.pixelsForCoordinate: 1.4400 s
2022-01-05 09:31:28.466 5424-5424/com.ixlab.mapbox.wemap E/info: -->v10 mapboxMap.pixelsForCoordinates: 1.5240 s
2022-01-05 09:31:29.971 5424-5424/com.ixlab.mapbox.wemap E/info: -->v10 mapboxMap.pixelsForCoordinate: 1.5040 s
------------------------ v10.1.0 ---------------------
2022-01-05 09:38:51.346 6579-6579/com.ixlab.mapbox.wemap E/info: -->v10 mapboxMap.pixelsForCoordinates: 1.3830 s
2022-01-05 09:38:52.842 6579-6579/com.ixlab.mapbox.wemap E/info: -->v10 mapboxMap.pixelsForCoordinate: 1.4960 s
2022-01-05 09:39:19.172 7258-7258/com.ixlab.mapbox.wemap E/info: -->v10 mapboxMap.pixelsForCoordinates: 1.8170 s
2022-01-05 09:39:20.631 7258-7258/com.ixlab.mapbox.wemap E/info: -->v10 mapboxMap.pixelsForCoordinate: 1.4580 s
2022-01-05 09:39:40.060 7775-7775/com.ixlab.mapbox.wemap E/info: -->v10 mapboxMap.pixelsForCoordinates: 1.6880 s
2022-01-05 09:39:41.548 7775-7775/com.ixlab.mapbox.wemap E/info: -->v10 mapboxMap.pixelsForCoordinate: 1.4880 s
------------------------ v10.2.0 ---------------------
2022-01-05 09:45:48.496 9711-9711/com.ixlab.mapbox.wemap E/info: -->v10 mapboxMap.pixelsForCoordinates: 1.8430 s
2022-01-05 09:45:50.035 9711-9711/com.ixlab.mapbox.wemap E/info: -->v10 mapboxMap.pixelsForCoordinate: 1.5390 s
2022-01-05 09:46:06.665 10258-10258/com.ixlab.mapbox.wemap E/info: -->v10 mapboxMap.pixelsForCoordinates: 1.8450 s
2022-01-05 09:46:08.178 10258-10258/com.ixlab.mapbox.wemap E/info: -->v10 mapboxMap.pixelsForCoordinate: 1.5120 s
2022-01-05 09:46:19.786 10771-10771/com.ixlab.mapbox.wemap E/info: -->v10 mapboxMap.pixelsForCoordinates: 1.5700 s
2022-01-05 09:46:21.322 10771-10771/com.ixlab.mapbox.wemap E/info: -->v10 mapboxMap.pixelsForCoordinate: 1.5350 s
Any solution pls ?
any updates?
can you try this with https://github.com/mapbox/mapbox-maps-android/releases/tag/v11.0.0?