Incredibly slow performance due to heavy topography files
See original GitHub issueHi, i’m loading the full world map to show all the users of my application spread across the globe. I’m using one of the topography file which is ~4MB in size. This is my component:
import PropTypes from 'prop-types';
import React from 'react';
import { ComposableMap, Geographies, Geography, Marker } from 'react-simple-maps';
const worldMapJson = require('../../../images/world-10m.json');
const WorldMap = ({ markers }) => {
return (
<ComposableMap
projection="geoMercator"
projectionConfig={{
scale: 100,
}}
height={400}
>
<Geographies geography={worldMapJson}>
{({ geographies }) =>
geographies.map(geo => <Geography key={geo.rsmKey} geography={geo} fill="#EAEAEC" stroke="#888" />)
}
</Geographies>
{markers.map(({ key, coordinates }) => (
<Marker key={key} coordinates={coordinates}>
<circle r={3} fill="#3ca" stroke="#065" strokeWidth={1} />
</Marker>
))}
</ComposableMap>
);
};
WorldMap.propTypes = {
markers: PropTypes.array.isRequired,
};
export default WorldMap;
I’ve tried with 50 markers then 5000 markers, the performance is equally awful. The who page stutters when scrolling through this map. It is specially slow when my curser is anywhere on the map when i’m scrolling the page. I’ve downloaded the file locally and then using it but it made no difference. Can you help with tips to improving performance?
It looks gorgeous though.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Placing new spot elevations on topography incredibly slow
Solved: As the attached GIF shows, when placing spot elevations on topographic elements the machine grinds for like 30s on each spot.
Read more >New Guy - Lots of Slow Processes
I'd like to create a map of BLM roads and trails where my group camps out. I've worked through the tutorial with good...
Read more >How to improve Edit Surface (topography) performance
I'm using Revit 2011 and am modeling a large development with a ... Is the performance hit due to the area of the...
Read more >Optimizing Mesh Performance
It can also hinder performance if used incorrectly. Meshes that are overly complex take much longer to regenerate due to the number of...
Read more >Question - Unity Terrain performances on Oculus Quest 2
As shown in the screencap, the performance is very poor even with no textures ... Although an equally large terrain made in blender...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @saranshbansal,
With around 5000 users the performance drop is quite normal since SVG has natural limits to how many items you can display in a way that will still be performant. Once you get into the 1000s it can get pretty bad regardless of what you do. With 50 there should definitely be no issues though.
However, there are a couple of things you could try:
The world-10m file is extremely detailed. It’s definitely too much detail for a map showing user dots on a world map like yours. I would try the world-110m instead. This will make the biggest difference.
There is a huge performance drop with svg when using stroke on paths. If you don’t necessarily need the country borders, you could try removing the stroke. If the country borders are important, then of course this is not an option.
If hovering on the geographies is not important, you could also add a
style={{ pointerEvents: "none" }}
css rule on theGeographies
component. That would bypass all events when hovering over the geographies. Markers would still react properly though.I don’t know about the rest of the code on the page, but you could also check to make sure that there are no rerenders happening on the parent component (could be the case if you use parallax or some kind of other scrolling events). If the map is being rerendered on scroll that would definitely make the page stutter.
Small side note, I would recommend not using the Mercator projection. It’s not the best projection to use for a world map for a number of reasons (e.g. weird size relationships between countries). The default geoEqualEarth projection is a better option.
https://www.vox.com/world/2016/12/2/13817712/map-projection-mercator-globe
https://www.axismaps.com/guide/general/map-projections/
https://www.esri.com/about/newsroom/arcuser/equal-earth/
Hope the above helps you improve the performance.
Hey thanks for all the suggestions. Using a lighter version of the topography and removing strokes gave a huge boost in performance.
On top of that, I tweaked my response as well to load as less data as possible. Some of the coordinates were extremely close to each other so I identified and removed all those cases and reduced the number of markers from ~5000 to ~1100. It works really well now.