-
Notifications
You must be signed in to change notification settings - Fork 938
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
Performance with many markers #224
Conversation
Now GoogleMapHolder just renders children, and defines a context to provide the reference to itself. In this way, to request the original google map obejct, it is only necessary to request it from the context. This improves rendering of 3000 markers by 3 seconds.
…his incresases the performance of the map, when rendering many markers
Why is this not merged yet ? |
+1 |
Performance many markers
@rewop after taking a deeper look into your solution, I noticed that if you wanted to update the marker in any way (size, color, icon, etc) you cant. I would suggest maybe being able to pass in your own function to CDU and that way you can control all updates based on which features you may want. You could also do a comparison of each marker, but that may also have performance issues. |
@vinceprofeta I worked on this PR quite long ago, and I need a moment to catch up with the changes. I see your point, and it is indeed a good one. Do you have an example that I can use to reproduce the use case? I will work on this asap. |
|
@rewop within render I have a loop to create the markers and within the loop I have a function to determine whether that icon should be the active icon (bigger and a different color). For your example you could just adjust the size of the marker. |
@tomchentw Do you have an opinion on this? Making this update significantly helped performance, and would love to get a fix in production. |
fork merge
@vinceprofeta @rewop i needed some features to quickly put them into development/production so i created a repo based on this one. https://www.npmjs.com/package/react-gl-maps if you want to pull this i will be glad. |
@cristiandley thanks. I have had a really busy week at work, and I couldn't put myself into it yet. I hope by the end of this week to manage. |
NOTE: I updated the description to better explain my solution here. |
@rewop Thanks for all the hard work for this. Much appreciated. Would you please revert the changes made to Also, why adding |
@@ -88,6 +99,10 @@ export default class Marker extends Component { | |||
} | |||
} | |||
|
|||
shouldComponentUpdate() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why adding shouldComponentUpdate
to Marker
component?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first this was my approach to try fix performance, that is why I implemented it. However, later I didn't remove it because it because I thought that the marker doesn't need to be updated, unless it is completely replaced.
However for the sake of performance, this shouldComponentUpdate
is not needed.
@tomchentw what do you think? I can push a change for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this for this PR. I want to implement sCU
for components in another pull requests, thus making changes as small as possible.
@tomchentw I reverted the |
@tomchentw all changes done |
@@ -14,6 +15,10 @@ import { | |||
markerEventPropTypes, | |||
} from "./creators/MarkerCreator"; | |||
|
|||
import GoogleMapHolder from "./creators/GoogleMapHolder"; | |||
|
|||
import _ from 'lodash'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove lodash
for now.
@@ -84,6 +84,7 @@ | |||
"can-use-dom": "^0.1.0", | |||
"google-maps-infobox": "^1.1.13", | |||
"invariant": "^2.1.1", | |||
"lodash": "^4.12.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove lodash
for now.
@rewop thanks a LOT! Just one more thing to do then we're all set! |
@tomchentw done the changes. I also linted, to make sure I didn't miss anything. Let me know if more is needed. |
@@ -84,8 +84,6 @@ | |||
"can-use-dom": "^0.1.0", | |||
"google-maps-infobox": "^1.1.13", | |||
"invariant": "^2.1.1", | |||
"lodash": "^4.12.0", | |||
"lodash.isequal": "^3.0.4", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh no. You have to keep lodash.isequal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh. I knew I had to keep it. Strange it was removed because I double checked. Must have made a mistake. Going to fix it now.
@rewop please bring back |
Looks great so far. I'll review this again tomorrow morning and merge it. |
I've tested on my local and it's working great. Thanks again! |
Released v5.0.0. This version( |
This PR solves the performance problems on the map, when rendering many markers.
Problem
The problem is that every component in the module needs a reference to the mapHolder instance to perform some operation on the google map.
GoogleMapHolder passes itself down to the children using props, but to do so it always needs to clone all the children that is rendering.
So if you render many markers, GoogleMapHolder clones all the markers every time its render function fires.
Solution
To solve the issue, I place the mapHolder instance in a context instead. This way all the components down the tree can access the mapHolder instance just by requesting it from the context (code for the marker).
This way the cloning of each child is not needed and the performance are (almost) the same if you used the plain google map library.
An example is the following:
Each click on the marker on this map, takes more than 3 seconds to update it. This pr aims at solving this problem, and dramatically improve the performance issues.
Resolve #135