rnmapbox / rnmapbox/maps

[Bug]: invisible LocationPuck causing high CPU load

Open
#3,787 6 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug 🪲 iOS
Dominant language
Kotlin
Stars
2.9k
Forks
947
Avg merge
6d 37m
Merged PRs (30d)
1

Description

Mapbox Implementation

Mapbox

Mapbox Version

11.8.0

React Native Version

0.76.6

Platform

iOS

@rnmapbox/maps version

10.1.31

Standalone component to reproduce
import React from 'react';
import {
  MapView,
  ShapeSource,
  LineLayer,
  Camera,
  LocationPuck,
} from '@rnmapbox/maps';

const aLine = {
  type: 'LineString',
  coordinates: [
    [-74.00597, 40.71427],
    [-74.00697, 40.71527],
  ],
};

class BugReportExample extends React.Component {
  render() {
    return (
      <MapView style={{flex: 1}}>
        <Camera centerCoordinate={[-74.00597, 40.71427]} zoomLevel={14} />
        <LocationPuck puckBearingEnabled={true} visible={false} />
        <ShapeSource id="idStreetLayer" shape={aLine}>
          <LineLayer id="idStreetLayer" />
        </ShapeSource>
      </MapView>
    );
  }
}
Observed behavior and steps to reproduce

When adding an <LocationPuck visible={false} /> and feeding continuous GPS updates with Xcode I can see a pretty high CPU load on iOS.

Image

Expected behavior

No additional CPU load when LocationPuck is not visible.

Notes / preliminary analysis

This is caused since an 1x1 empty image is used inside RNMBXNativeUserLocation when invisible is true. Mapbox then animates this invisible image causing a pretty high load for nothgin.
I don't know the reason for that implementation but from my point of view it should be fine to just set location.options.puckType to nil.

https://github.com/rnmapbox/maps/blob/main/ios/RNMBX/RNMBXNativeUserLocation.swift#L144

Additional links and references

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with ios/RNMBX/RNMBXNativeUserLocation.swift around line 144 and inspect how an invisible LocationPuck is configured. Reproduce the issue with the provided React Native example and continuous GPS updates on iOS; done means an invisible puck no longer adds the reported CPU load.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, javascript, react-native, swift
Domain
mobile-dev, performance
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.