Skip to content

Commit 84cf45d

Browse files
vadzim-vysgithub-actions[bot]
authored andcommitted
Performance sections clarification (#9350)
GitOrigin-RevId: 8f31cf8b32303b7b9877102a37556ec0c2fab0b9
1 parent 8701d61 commit 84cf45d

3 files changed

Lines changed: 76 additions & 62 deletions

File tree

navigation/src/main/java/com/mapbox/navigation/core/directions/session/MapboxDirectionsSession.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import androidx.annotation.VisibleForTesting
44
import com.mapbox.api.directions.v5.models.DirectionsRoute
55
import com.mapbox.api.directions.v5.models.RouteOptions
66
import com.mapbox.navigation.base.internal.RouteRefreshRequestData
7+
import com.mapbox.navigation.base.internal.performance.PerformanceTracker
78
import com.mapbox.navigation.base.internal.route.routeOptions
89
import com.mapbox.navigation.base.route.NavigationRoute
910
import com.mapbox.navigation.base.route.NavigationRouterCallback
@@ -57,8 +58,10 @@ internal class MapboxDirectionsSession(
5758
routesUpdatedResult = it
5859
}
5960

60-
onSetNavigationRoutesFinishedObservers.forEach {
61-
it.onRoutesChanged(result)
61+
PerformanceTracker.trackPerformance("MapboxDirectionsSession-dispatch-onRoutesChanged") {
62+
onSetNavigationRoutesFinishedObservers.forEach {
63+
it.onRoutesChanged(result)
64+
}
6265
}
6366
}
6467

navigation/src/main/java/com/mapbox/navigation/core/trip/session/MapboxTripSession.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -717,9 +717,7 @@ internal class MapboxTripSession(
717717
}
718718
}
719719
}
720-
PerformanceTracker.trackPerformance("MapboxTripSession#updateRouteProgress") {
721-
updateRouteProgress(routeProgress, triggerObserver)
722-
}
720+
updateRouteProgress(routeProgress, triggerObserver)
723721
triggerVoiceInstructionEvent(routeProgress, status)
724722
isOffRoute = tripStatus.navigationStatus.routeState == RouteState.OFF_ROUTE
725723
}

ui-maps/src/main/java/com/mapbox/navigation/ui/maps/camera/data/MapboxNavigationViewportDataSource.kt

Lines changed: 70 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import com.mapbox.maps.ScreenBox
1717
import com.mapbox.maps.toCameraOptions
1818
import com.mapbox.maps.util.isEmpty
1919
import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI
20+
import com.mapbox.navigation.base.internal.performance.PerformanceTracker
2021
import com.mapbox.navigation.base.internal.utils.areSameRoutes
2122
import com.mapbox.navigation.base.internal.utils.isSameRoute
2223
import com.mapbox.navigation.base.route.NavigationRoute
@@ -373,7 +374,9 @@ class MapboxNavigationViewportDataSource private constructor(
373374
fun evaluate() {
374375
mapsSizeReadyCancellable?.cancel()
375376
mapsSizeReadyCancellable = mapSizeReadyCallbackHelper.onMapSizeInitialized {
376-
evaluateImpl()
377+
PerformanceTracker.trackPerformance("MapboxNavigationViewportDataSource#evaluateImpl") {
378+
evaluateImpl()
379+
}
377380
}
378381
}
379382

@@ -417,7 +420,9 @@ class MapboxNavigationViewportDataSource private constructor(
417420
* @see [evaluate]
418421
*/
419422
fun onRouteChanged(route: NavigationRoute) {
420-
onRoutesChanged(listOf(route))
423+
PerformanceTracker.trackPerformance("MapboxNavigationViewportDataSource#onRouteChanged") {
424+
onRoutesChanged(listOf(route))
425+
}
421426
}
422427

423428
internal fun onRoutesChanged(routes: List<NavigationRoute>) {
@@ -444,61 +449,10 @@ class MapboxNavigationViewportDataSource private constructor(
444449
* @see [evaluate]
445450
*/
446451
fun onRouteProgressChanged(routeProgress: RouteProgress) {
447-
this.routeProgress = routeProgress
448-
val currentRoute = this.navigationRoute
449-
if (currentRoute == null) {
450-
logW(
451-
"You're calling #onRouteProgressChanged but you didn't call #onRouteChanged.",
452-
LOG_CATEGORY,
453-
)
454-
clearProgressData()
455-
return
456-
} else if (!currentRoute.directionsRoute.isSameRoute(routeProgress.route)) {
457-
logE(
458-
"Provided route (#onRouteChanged) and navigated route " +
459-
"(#onRouteProgressChanged) are not the same. " +
460-
"Aborting framed geometry updates based on route progress.",
461-
LOG_CATEGORY,
462-
)
463-
clearProgressData()
464-
return
465-
}
466-
467-
ifNonNull(
468-
routeProgress.currentLegProgress,
469-
routeProgress.currentLegProgress?.currentStepProgress,
470-
) { currentLegProgress, currentStepProgress ->
471-
isFramingManeuverProperty.fallback = isFramingManeuver(
472-
routeProgress,
473-
options.followingFrameOptions,
474-
)
475-
followingPitchProperty.fallback = if (isFramingManeuverProperty.get()) {
476-
ZERO_PITCH
477-
} else {
478-
options.followingFrameOptions.defaultPitch
479-
}
480-
481-
pointsToFrameOnCurrentStep = options.followingFrameOptions.framingStrategy
482-
.getPointsToFrameOnCurrentStep(
483-
routeProgress,
484-
options.followingFrameOptions,
485-
averageIntersectionDistancesOnRoute,
486-
)
487-
488-
pointsToFrameAfterCurrentStep = options.followingFrameOptions.framingStrategy
489-
.getPointsToFrameAfterCurrentManeuver(
490-
routeProgress,
491-
options.followingFrameOptions,
492-
postManeuverFramingPoints,
493-
)
494-
495-
overviewViewportDataSource.onRouteProgressChanged(routeProgress)
496-
} ?: run {
497-
logE(
498-
"You're calling #onRouteProgressChanged with empty leg or step progress.",
499-
LOG_CATEGORY,
500-
)
501-
clearProgressData()
452+
PerformanceTracker.trackPerformance(
453+
"MapboxNavigationViewportDataSource#onRouteProgressChanged",
454+
) {
455+
onRouteProgressChangedInternal(routeProgress)
502456
}
503457
}
504458

@@ -568,6 +522,65 @@ class MapboxNavigationViewportDataSource private constructor(
568522
evaluate()
569523
}
570524

525+
private fun onRouteProgressChangedInternal(routeProgress: RouteProgress) {
526+
this.routeProgress = routeProgress
527+
val currentRoute = this.navigationRoute
528+
if (currentRoute == null) {
529+
logW(
530+
"You're calling #onRouteProgressChanged but you didn't call #onRouteChanged.",
531+
LOG_CATEGORY,
532+
)
533+
clearProgressData()
534+
return
535+
} else if (!currentRoute.directionsRoute.isSameRoute(routeProgress.route)) {
536+
logE(
537+
"Provided route (#onRouteChanged) and navigated route " +
538+
"(#onRouteProgressChanged) are not the same. " +
539+
"Aborting framed geometry updates based on route progress.",
540+
LOG_CATEGORY,
541+
)
542+
clearProgressData()
543+
return
544+
}
545+
546+
ifNonNull(
547+
routeProgress.currentLegProgress,
548+
routeProgress.currentLegProgress?.currentStepProgress,
549+
) { currentLegProgress, currentStepProgress ->
550+
isFramingManeuverProperty.fallback = isFramingManeuver(
551+
routeProgress,
552+
options.followingFrameOptions,
553+
)
554+
followingPitchProperty.fallback = if (isFramingManeuverProperty.get()) {
555+
ZERO_PITCH
556+
} else {
557+
options.followingFrameOptions.defaultPitch
558+
}
559+
560+
pointsToFrameOnCurrentStep = options.followingFrameOptions.framingStrategy
561+
.getPointsToFrameOnCurrentStep(
562+
routeProgress,
563+
options.followingFrameOptions,
564+
averageIntersectionDistancesOnRoute,
565+
)
566+
567+
pointsToFrameAfterCurrentStep = options.followingFrameOptions.framingStrategy
568+
.getPointsToFrameAfterCurrentManeuver(
569+
routeProgress,
570+
options.followingFrameOptions,
571+
postManeuverFramingPoints,
572+
)
573+
574+
overviewViewportDataSource.onRouteProgressChanged(routeProgress)
575+
} ?: run {
576+
logE(
577+
"You're calling #onRouteProgressChanged with empty leg or step progress.",
578+
LOG_CATEGORY,
579+
)
580+
clearProgressData()
581+
}
582+
}
583+
571584
private fun clearProgressData() {
572585
followingPitchProperty.fallback = options.followingFrameOptions.defaultPitch
573586
pointsToFrameOnCurrentStep = emptyList()

0 commit comments

Comments
 (0)