maps icon indicating copy to clipboard operation
maps copied to clipboard

[Bug]: invisible LocationPuck causing high CPU load

Open g4rb4g3 opened this issue 11 months ago • 6 comments

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

g4rb4g3 avatar Feb 21 '25 10:02 g4rb4g3

me too!

kaito0228 avatar Feb 25 '25 02:02 kaito0228

When I launch rnmapbox and use it while moving for about 20 minutes, the CPU processing freezes. The map itself can still be operated, suggesting that map operations might be processed by the GPU.

I'm using the latest versions of rnmapbox (10.1.37) and mapbox-maps-ios (11.10.1).

kaito0228 avatar Feb 28 '25 02:02 kaito0228

Any thoughts on this from your side @mfazekas ? As mentioned I have no idea why the empty image is in place and from my testing it is fine to set location.options.puckType to nil. Should I do a PR removing the empty image and just setting location.options.puckType = nil?

g4rb4g3 avatar Apr 05 '25 15:04 g4rb4g3

@g4rb4g3 I think the reason for empty image, is I think that follow user location was only working if there was a location puck. Not sure if it's still the case.

mfazekas avatar Oct 18 '25 15:10 mfazekas

@g4rb4g3 also why don't you just remove the LocationPuck component?

{false && <LocationPuck puckBearingEnabled={true} visible={false} />}

mfazekas avatar Oct 18 '25 16:10 mfazekas

add a console.log to onMapIdle - my phone turned into a heating pad for a second..

onMapIdle(state) {
  console.log("onMapIdle called")
}

warmfire540 avatar Oct 18 '25 16:10 warmfire540