question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incredibly slow performance due to heavy topography files

See original GitHub issue

Hi, 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. CE538FE4-804C-4E92-A8D7-9147620ECC52

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
zimrickcommented, Jul 20, 2020

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:

  1. 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.

  2. 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.

  3. If hovering on the geographies is not important, you could also add a style={{ pointerEvents: "none" }} css rule on the Geographies component. That would bypass all events when hovering over the geographies. Markers would still react properly though.

  4. 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.

1reaction
saranshbansalcommented, Jul 20, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found