Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Location animators memory and CPU optimizations - #13678

Merged
LukasPaczos merged 4 commits into
masterfrom
lp-animators-battery-optimization
Jan 30, 2019
Merged

LukasPaczos merged 4 commits into
masterfrom
lp-animators-battery-optimization

Conversation

@LukasPaczos

@LukasPaczos LukasPaczos commented Jan 7, 2019 •

Copy link
Copy Markdown
Contributor

This PR adds an option to decrease the output rate of animated fractions for location camera's and puck's LatLng and bearing values and since on higher zoom levels those values do not need to be precise to still render visually correct, without animation "stuttering". Keeping the animation rate low decreases the CPU's utilization, which should directly impact energy consumption.

Below are before and after screenshots of average CPU utilization while animating a navigation puck on zoom level 15 and tilt 45 which are typical navigation settings for driving around town.

screenshot 2019-01-04 at 16 19 31

screenshot 2019-01-04 at 16 18 44

Testing shows a CPU utilization on a Pixel 2 XL down about 11 percentage points on average - this is ~34% less CPU stress caused by our map and animations.

The higher we go with a zoom level the more we can throttle the animations. On zoom levels around 13, I could go down to as low as average 12% CPU utilization without impacting the UX.

In pair with decreasing the animation rate, this PR refactors the animator coordinator to only animate values that are going to be consumed - for example, camera bearing animator is not going to run if the CameraMode is set to TRACKING only.

Example usage:

mapboxMap.addOnCameraIdleListener(new MapboxMap.OnCameraIdleListener() {
  @Override
  public void onCameraIdle() {
    double zoom = mapboxMap.getCameraPosition().zoom;
    int maxAnimationFps;
    if (zoom < 5) {
      maxAnimationFps = 2;
    } else if (zoom < 10) {
      maxAnimationFps = 5;
    } else if (zoom < 15) {
      maxAnimationFps = 7;
    } else if (zoom < 18) {
      maxAnimationFps = 15;
    } else {
      maxAnimationFps = 60;
    }
    locationComponent.setMaxAnimationFps(maxAnimationFps);
  }
});

TODO:

  • expose OnRenderModeChanged listener
  • test coverage
  • docs

@LukasPaczos LukasPaczos added Android Mapbox Maps SDK for Android ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold in progress labels Jan 7, 2019
@LukasPaczos LukasPaczos added this to the android-v7.1.0 milestone Jan 7, 2019
@LukasPaczos LukasPaczos modified the milestones: android-v7.1.0, android-v7.2.0 Jan 28, 2019
@LukasPaczos
LukasPaczos force-pushed the lp-animators-battery-optimization branch 2 times, most recently from d782697 to 60dbe0c Compare January 29, 2019 13:11
@LukasPaczos LukasPaczos removed in progress ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold labels Jan 29, 2019
@LukasPaczos
LukasPaczos force-pushed the lp-animators-battery-optimization branch from 0a5cd7c to 6b5b350 Compare January 29, 2019 14:11
@LukasPaczos
LukasPaczos requested a review from tobrun January 29, 2019 14:16
@LukasPaczos

Copy link
Copy Markdown
Contributor Author

This one is ready for a review.

ezgif com-video-to-gif 26

@tobrun tobrun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looks good! one small comment and looping @danesfeder in for additional 👀

@tobrun
tobrun requested a review from danesfeder January 30, 2019 12:49
@LukasPaczos
LukasPaczos force-pushed the lp-animators-battery-optimization branch from 6b5b350 to 3e5e4ed Compare January 30, 2019 12:55
@LukasPaczos
LukasPaczos force-pushed the lp-animators-battery-optimization branch from 3e5e4ed to 246dbbe Compare January 30, 2019 14:18

@danesfeder danesfeder left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@LukasPaczos awesome work here - excited to utilize these optimization in the navigation SDK ✅

@LukasPaczos
LukasPaczos merged commit d8bd594 into master Jan 30, 2019
@LukasPaczos
LukasPaczos deleted the lp-animators-battery-optimization branch January 30, 2019 15:13
@LukasPaczos LukasPaczos modified the milestones: android-v7.2.0, release-k Feb 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Android Mapbox Maps SDK for Android

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants