-
Notifications
You must be signed in to change notification settings - Fork 935
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 issues when changing a marker icon with lots of markers #135
Comments
Could you provide me a gist that contains the mock marker data so that I could test it out? Thanks! |
At first glance, I didn't see any problem in your code. You have |
https://gist.github.com/hovatterz/be265738f8a297bad4df You can just set the center point to any one of those lat/lon points. I fixed the markers zIndex seeming to change on hover by specifying a zIndex for each one. I think it would still be preferable for them to not re-render though. The defaultZoom is set to 13 |
@hovatterz I just setup a branch in the example repo here: http://git.io/vWllh. As I ran it on my computer, I didn't experience any lags nor delays. Could you take a look and modify on the branch as your wish? |
I observe something like that. My map component has a list of polylines and markers among other props and I see In the rest of my app I avoided such situations by using Immutable.js for props and turning PureRenderMixin on. I wish all markers and polylines were Pure components here as well, or at least shouldComponentUpdate could have been customised for them. |
@ksavenkov ideally that should be the case. However, since we have I'll try to fix this in the next roadmap. |
Shouldn't setting I am facing performance problems too with lots of markers (~100), but their markers aren't re-rendering on every prop change. |
@channikhabra maybe that will do the trick. Make sure to check |
Hey Tom, I made an embarrassing mistake. I thought I was commenting on google-map-react project (https://github.com/istarkov/google-map-react/). We're having some performance problems and a colleague mentioned this issue. I mistook it for similarly named google-map-react which we're using. Sorry for the inconvenience. |
@channikhabra no worries. |
I came across the same performance problem, and I believe it is a great stopper to use this fantastic module in production. I have been trying a map with the more than 3000 markers. The map would use In my map, every time a marker is clicked, an overlay is shown on the map to visualise the information related to the marker. With so many markers, the map becomes very slow every time is clicked. I thought the problem was with the Looking at the code, it looks like the As an idea, I am trying to add the puremixin to the I see that the folder @tomchentw before I open a new issue with this problem, could you explain how to run the examples so that the changes are reflected? |
I tried to investigate further. I run this example with the map: import React, { Component } from "react";
import { GoogleMapLoader, GoogleMap, Marker, OverlayView } from "react-google-maps";
const STYLES = {
mapContainer: {
height: "400px"
},
overlayView: {
background: "white",
border: "1px solid #ccc",
padding: 15
}
};
function getRandomInRange(from, to, fixed) {
return (Math.random() * (to - from) + from).toFixed(fixed) * 1;
}
function createLatLng() {
return {
lat: getRandomInRange(-90, 90),
lng: getRandomInRange(-180, 180)
};
}
function createMarker(index) {
return {
position: createLatLng(),
index
};
}
function getMarkers() {
let markers = [];
for (let i = 0; i < 3000; i++) {
markers = [
...markers,
createMarker(i)
];
}
return markers;
}
class MapTest extends Component {
constructor() {
super();
this.state = {
markers: []
};
}
componentDidMount() {
this.setState({
markers: getMarkers()
});
}
onSelectMarker(marker) {
this.setState({
selectedMarker: marker
});
}
onCloseOverlay() {
this.setState({
selectedMarker: null
});
}
render() {
return (
<GoogleMapLoader
containerElement={
<div {... this.props} style={STYLES.mapContainer} />
}
googleMapElement={
<GoogleMap
defaultZoom={7}
defaultCenter={{
lat: 52.3702157,
lng: 4.8951679
}}
>
{this.state.selectedMarker &&
<OverlayView
position={this.state.selectedMarker.position}
mapPaneName={OverlayView.OVERLAY_MOUSE_TARGET}
>
<div style={STYLES.overlayView}>
<h1>OverlayView</h1>
<p>Marker: {this.state.selectedMarker.index}</p>
<button onClick={() => this.onCloseOverlay()}>
Close me
</button>
</div>
</OverlayView>
}
{this.state.markers.map((marker, index) => {
return (
<Marker
{...marker}
onClick={() => this.onSelectMarker(marker)}
key={index}
/>
);
})}
</GoogleMap>
}
/>
);
}
} With this example every click on the marker, as well as click on the overlay button, are very slow. I tried to implement the Digging further I noticed that in the render function of |
@tomchentw I made an attempt to use context to increase performance, and it worked very fine. You can check it in the PR I linked. However, I still need to run the examples, to make sure nothing has been broken. Looking forward to hearing your thoughts about it :) |
@rewop Could you explain, what do you mean with "context"? |
Are you using this? https://facebook.github.io/react/docs/context.html
|
@sohibul @wedneyyuri Yes I used react context api. I added the links my explanation here. To summarise my implementation in #224: ProblemThe 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 the its render function fires. SolutionTo 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. |
* Improved performance of rendering many markers/components on the map * Closes #135 * Closes #210 * Closes #216 BREAKING CHANGE: If you're just using the library and didn't make custom components before, feel free to ignore this implementation changes. Now, mapHolderRef for each component are now passed in via context. This doesn't affect all components interface in general. But if you do custom components before and relies on the implementation of react-google-maps, you should be aware of this and make some changes.
Hello @tomchentw , is this PR exist in the current version 9.0.0 please ? cause i still face performance issue with 2000 marker on map !! thanks a lot . |
I have a dataset of about 119 items (other maps will have more), and each item is a marker on the Google map. It seems that when I change the icon for one marker (on hover) it removes and adds every single marker. This leads to some slowness and slight flickering.
Is there some way I can avoid this? Sorry if I'm missing something obvious.
The text was updated successfully, but these errors were encountered: