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

Expose tracksViewChange and icon property to improve some performance issues #1491

Closed
wants to merge 3 commits into from

Conversation

PhamBaTho
Copy link

@PhamBaTho PhamBaTho commented Jul 19, 2017

Expose tracksViewChanges property of GMSMarker. By default, this property is YES.

Setting tracksViewChange to NO appropriately can solve some performance issues causing high CPU load on iOS (e.g. #1031 , #1176).

The followings are some guidelines relating to tracksViewChange I extracted from Google Maps SDK documentation:

  • The UIView can be demanding on resources when tracksViewChanges is set to YES, which may result in increased battery usage. In comparison, a single frame UIImage is static and does not need to be re-rendered.
  • Some devices may struggle to render the map if you have many markers on screen, and each marker has its own UIView, and all markers are tracking changes at the same time.
  • To decide when to set the tracksViewChanges property, you should weigh up performance considerations against the advantages of having the marker redrawn automatically. For example:
    • If you have a series of changes to make, you can change the property to YES then back to NO.
    • When an animation is running or the contents are being loaded asynchronously, you should keep the property set to YES until the actions are complete.

Please note that this property has no effect if iconView of marker is nil. In other words, I don't think we have any issue with performance if we use default marker.

I have tested on iOS simulator with many use cases like adding many markers on maps, drawing polyline between markers, animating custom markers... and the CPU remains in good health when the map is idle.

Sample usage:

<MapView.Marker
   tracksViewChanges={ false }
   anchor={ { x: 1, y: 1 } }
   coordinate={ {
      longitude: location.longitude,
      latitude: location.latitude,
   } }>
   { this.renderMarker() }
</MapView.Marker>

@PhamBaTho
Copy link
Author

PhamBaTho commented Jul 20, 2017

UPDATE:
I have just updated this PR a bit. I'm exposing additionally icon property. It's equivalent to icon property of GMSMarker Class.

The image property is great, it can cover most of use cases. Though, I believe that using icon property still has an advantage over image property in term of performance, battery usage... because it doesn't trigger tracksViewChanges which has no effect if iconView is nil.

We still need to have a better naming between icon and existing image to make them less confusing.

@PhamBaTho PhamBaTho changed the title Expose tracksViewChange property to improve some performance issues Expose tracksViewChange and icon property to improve some performance issues Jul 20, 2017
@@ -260,13 +273,20 @@ class MapMarker extends React.Component {
image = image.uri;
}

let icon;
if (this.props.icon) {

Choose a reason for hiding this comment

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

I would refactor this to ternary if statement :)

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

@heysailor
Copy link
Contributor

Thanks for this. Could you give a full example of use with the icon property?

@juergengunz
Copy link

juergengunz commented Aug 30, 2017

i discovered that if i use < image > the images are not being displayed on google maps (ios)... when i use the image property it works fine but i am not able to resize the images

@krabbypattified
Copy link

+1 would really like to see these optimizations in my app!

@compojoom
Copy link
Contributor

@PhamBaTho - how do I add your changes to an existing project? I tried directly modifying the AirGoogleMaps in the project in xCode, but then I get a compile error:
"Linker command failed with exit code 1"

@@ -17,6 +18,7 @@
| `identifier` | `String` | | An identifier used to reference this marker at a later date.
| `rotation` | `Float` | | A float number indicating marker's rotation angle, in degrees.
| `draggable` | `<null>` | | This is a non-value based prop. Adding this allows the marker to be draggable (re-positioned).
| `tracksViewChanges` | `Boolean` | | Controls whether the icon for this marker should be redrawn every frame.
Copy link
Contributor

Choose a reason for hiding this comment

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

@PhamBaTho Is this prop iOS only?

Copy link
Contributor

Choose a reason for hiding this comment

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

Only applicable for iOS. Android don't have issues with that.

* because it doesn't trigger tracksViewChanges.
* (tracksViewChanges is set to YES by default if iconView is not nil).
*/
icon: PropTypes.any,
Copy link
Contributor

Choose a reason for hiding this comment

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

@PhamBaTho Can you give this a more specific prop type?

@satori-ytolstoguzov
Copy link
Contributor

At what stage this PR? I use a fork with tracksViewChanges in my project for at least half a year while waiting to be merged.
@PhamBaTho Are you going to fix comments?

@rborn
Copy link
Collaborator

rborn commented Jan 12, 2018

@satori-ytolstoguzov if you could address the comments (if @PhamBaTho won't) I can have a look

@compojoom
Copy link
Contributor

compojoom commented Jan 12, 2018

@rborn @satori-ytolstoguzov @PhamBaTho - we've merged this back in November: #1705 and it exposes tracksViewChanges. Shouldn't we close this pull request? Or what is the difference here with pull request 1705?

@satori-ytolstoguzov
Copy link
Contributor

@compojoom It seems merged PR forgot to add that to the docs. Other than that I don't see any differences

@rborn
Copy link
Collaborator

rborn commented Jan 12, 2018

@satori-ytolstoguzov could you test if it's working and make a PR for documentation? I'll be here to merge it ❤️

@satori-ytolstoguzov
Copy link
Contributor

@rborn It's a busy day, will look into that on Monday. Also would you consider useful if I add one more bridged property: tracksInfoWindowChanges. It's only for iOS and without it Google Maps SDK ignores all changes in callout after first render.

@pqminh
Copy link

pqminh commented Jan 29, 2018

i'm testing on maps provider google and default.
rn 0.47.2
react-native-maps 0.17.1 | 0.19.0.
All of them don't working. I'm render maps about 700 markers. When use provider google, it's so slow and lag. And use provider default. It does not slow, but when press on random marker, callout is show behind the markers around...

@christopherdro
Copy link
Collaborator

trackViewChange prop has been added here: 78a36ac

christopherdro pushed a commit that referenced this pull request Jan 8, 2019
…erformance (#2650)

* Added icon property - #1491

* fixed MapMarker.js indentation

* Added support for Marker icon property on android

* Added support for Marker icon property on android
markdgo pushed a commit to markdgo/react-native-maps that referenced this pull request Mar 15, 2021
…erformance (#2650)

* Added icon property - react-native-maps/react-native-maps#1491

* fixed MapMarker.js indentation

* Added support for Marker icon property on android

* Added support for Marker icon property on android
MarcoAntonioAG pushed a commit to MarcoAntonioAG/React-map that referenced this pull request Mar 31, 2022
…erformance (#2650)

* Added icon property - react-native-maps/react-native-maps#1491

* fixed MapMarker.js indentation

* Added support for Marker icon property on android

* Added support for Marker icon property on android
joshpeterson30489 added a commit to joshpeterson30489/maps-develop-with-react-native that referenced this pull request Sep 30, 2022
…erformance (#2650)

* Added icon property - react-native-maps/react-native-maps#1491

* fixed MapMarker.js indentation

* Added support for Marker icon property on android

* Added support for Marker icon property on android
superstar1205 added a commit to superstar1205/Map-ReactNative that referenced this pull request Dec 26, 2022
…erformance (#2650)

* Added icon property - react-native-maps/react-native-maps#1491

* fixed MapMarker.js indentation

* Added support for Marker icon property on android

* Added support for Marker icon property on android
anthony0506 added a commit to anthony0506/react-native-maps that referenced this pull request Mar 19, 2023
…erformance (#2650)

* Added icon property - react-native-maps/react-native-maps#1491

* fixed MapMarker.js indentation

* Added support for Marker icon property on android

* Added support for Marker icon property on android
johney6767 pushed a commit to johney6767/Map-ReactNative that referenced this pull request May 31, 2023
…erformance (#2650)

* Added icon property - react-native-maps/react-native-maps#1491

* fixed MapMarker.js indentation

* Added support for Marker icon property on android

* Added support for Marker icon property on android
PainStaker0331 pushed a commit to PainStaker0331/react-native-maps that referenced this pull request Mar 3, 2024
…erformance (#2650)

* Added icon property - react-native-maps/react-native-maps#1491

* fixed MapMarker.js indentation

* Added support for Marker icon property on android

* Added support for Marker icon property on android
Super-CodeKing added a commit to Super-CodeKing/react_native_map that referenced this pull request Apr 26, 2024
…erformance (#2650)

* Added icon property - react-native-maps/react-native-maps#1491

* fixed MapMarker.js indentation

* Added support for Marker icon property on android

* Added support for Marker icon property on android
fairskyDev0201 pushed a commit to fairskyDev0201/react-native-maps that referenced this pull request Apr 29, 2024
…erformance (#2650)

* Added icon property - react-native-maps/react-native-maps#1491

* fixed MapMarker.js indentation

* Added support for Marker icon property on android

* Added support for Marker icon property on android
DavidLee0501 added a commit to DavidLee0501/React-Native-Map that referenced this pull request Aug 12, 2024
…erformance (#2650)

* Added icon property - react-native-maps/react-native-maps#1491

* fixed MapMarker.js indentation

* Added support for Marker icon property on android

* Added support for Marker icon property on android
This pull request was closed.
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.