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

Reduce default minimum frame rate to 20 fps #1819

Merged
merged 1 commit into from
Nov 7, 2018
Merged

Reduce default minimum frame rate to 20 fps #1819

merged 1 commit into from
Nov 7, 2018

Conversation

1ec5
Copy link
Contributor

@1ec5 1ec5 commented Nov 7, 2018

Reduced the default minimum frame rate (on battery power away from maneuvers) from 30 fps to 20 fps for improved battery performance. The frame rate while plugged in remains 30 fps, and the frame rate during the 10 seconds around a maneuver remains at 60 fps or 120 fps, depending on the device.

/cc @frederoni @JThramer

@1ec5 1ec5 self-assigned this Nov 7, 2018
@@ -24,7 +24,7 @@ open class NavigationMapView: MGLMapView, UIGestureRecognizerDelegate {

This property takes effect when the application has limited resources for animation, such as when the device is running on battery power. By default, this property is set to `MGLMapViewPreferredFramesPerSecond.lowPower`.
*/
@objc public var minimumFramesPerSecond = MGLMapViewPreferredFramesPerSecond.lowPower
@objc public var minimumFramesPerSecond = MGLMapViewPreferredFramesPerSecond(20)
Copy link
Contributor

@frederoni frederoni Nov 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍
>= 20 should be above the uncanny valley for most pair of eyes.

@1ec5
Copy link
Contributor Author

1ec5 commented Nov 7, 2018

Just to give a crude sense of the performance improvement, I simulated a half-mile-long (2-minute-long) route along surface streets while on battery power on an iPhone 8 running iOS 12. Over 20 seconds of straightaway, away from maneuvers, the Swift example application posted these times:

Frame rate CPU time % of control Notes
30fps 4.41 s 100% 344de5e (master)
20fps 3.04 s 68.9% This PR
5fps 1.10 s 24.9% Equivalent to before #1749

Overall, for the entire duration of the session (including the flying animation at the beginning), we posted these times:

Frame rate CPU time % of control Notes
30fps 44.48 s 100% 344de5e
20fps 37.46 s 84.2% This PR
5fps 23.28 s 52.3% Equivalent to before #1749

@1ec5 1ec5 added this to the v0.24.0 milestone Nov 7, 2018
@1ec5 1ec5 changed the title Reduced default minimum frame rate to 20 fps Reduce default minimum frame rate to 20 fps Nov 7, 2018
@1ec5
Copy link
Contributor Author

1ec5 commented Nov 7, 2018

For reference, I rigged a couple more test runs with some additional variations to the map style to illustrate the impact that they can have:

Setup Straightaway % Trip %
This PR 3.04 s 100% 37.46 s 100%
Night 3.04 s 100% 33.43 s 100%
No symbols 2.31 s 76.0% 24.52 s 65.5%
Blank 1.61 s 53.0% 19.72 s 52.6%
No symbols
diff --git a/MapboxNavigation/NavigationMapView.swift b/MapboxNavigation/NavigationMapView.swift
index 8cb35c71..760cbf83 100644
--- a/MapboxNavigation/NavigationMapView.swift
+++ b/MapboxNavigation/NavigationMapView.swift
@@ -968,31 +968,8 @@ open class NavigationMapView: MGLMapView, UIGestureRecognizerDelegate {
             return
         }
         
-        let streetsSourceIdentifiers: [String] = style.sources.compactMap {
-            $0 as? MGLVectorTileSource
-        }.filter {
-            $0.isMapboxStreets
-        }.map {
-            $0.identifier
-        }
-        
         for layer in style.layers where layer is MGLSymbolStyleLayer {
-            let layer = layer as! MGLSymbolStyleLayer
-            guard let sourceIdentifier = layer.sourceIdentifier,
-                streetsSourceIdentifiers.contains(sourceIdentifier) else {
-                continue
-            }
-            guard let text = layer.text else {
-                continue
-            }
-            
-            // Road labels should match road signage.
-            let locale = layer.sourceLayerIdentifier == "road_label" ? Locale(identifier: "mul") : nil
-            
-            let localizedText = text.mgl_expressionLocalized(into: locale)
-            if localizedText != text {
-                layer.text = localizedText
-            }
+            style.removeLayer(layer)
         }
     }
     
Blank
diff --git a/Examples/Swift/ViewController.swift b/Examples/Swift/ViewController.swift
index fa1a7ce9..f80defb6 100644
--- a/Examples/Swift/ViewController.swift
+++ b/Examples/Swift/ViewController.swift
@@ -282,7 +282,7 @@ extension ViewController: MGLMapViewDelegate {
             return
         }
         
-        self.mapView?.localizeLabels()
+//        self.mapView?.localizeLabels()
         
         if let routes = routes, let currentRoute = routes.first, let coords = currentRoute.coordinates {
             mapView.setVisibleCoordinateBounds(MGLPolygon(coordinates: coords, count: currentRoute.coordinateCount).overlayBounds, animated: false)
diff --git a/MapboxNavigation/NavigationMapView.swift b/MapboxNavigation/NavigationMapView.swift
index 8cb35c71..5eb5f5cf 100644
--- a/MapboxNavigation/NavigationMapView.swift
+++ b/MapboxNavigation/NavigationMapView.swift
@@ -968,31 +968,8 @@ open class NavigationMapView: MGLMapView, UIGestureRecognizerDelegate {
             return
         }
         
-        let streetsSourceIdentifiers: [String] = style.sources.compactMap {
-            $0 as? MGLVectorTileSource
-        }.filter {
-            $0.isMapboxStreets
-        }.map {
-            $0.identifier
-        }
-        
-        for layer in style.layers where layer is MGLSymbolStyleLayer {
-            let layer = layer as! MGLSymbolStyleLayer
-            guard let sourceIdentifier = layer.sourceIdentifier,
-                streetsSourceIdentifiers.contains(sourceIdentifier) else {
-                continue
-            }
-            guard let text = layer.text else {
-                continue
-            }
-            
-            // Road labels should match road signage.
-            let locale = layer.sourceLayerIdentifier == "road_label" ? Locale(identifier: "mul") : nil
-            
-            let localizedText = text.mgl_expressionLocalized(into: locale)
-            if localizedText != text {
-                layer.text = localizedText
-            }
+        for layer in style.layers {
+            style.removeLayer(layer)
         }
     }
     

@1ec5 1ec5 merged commit a5c58f2 into master Nov 7, 2018
@1ec5 1ec5 deleted the 1ec5-20fps branch November 7, 2018 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants