mapcrafter icon indicating copy to clipboard operation
mapcrafter copied to clipboard

Optimize TileRenderer tile image sorting

Open DaMatrix opened this issue 9 months ago • 1 comments

This contains three main changes:

  • Instead of sorting TileImages directly, we'll leave them unmodified and sort pointers to them instead. This makes the actual sorting much faster, since it only has to swap a pair of pointers after each comparison instead of a 56-byte class with a non-trivial move assignment operator.
  • std::sort() is now invoked separately for each of the sort modes, allowing the comparator to be inlined into the sorting code
  • Originally, a lot of time was being wasted resizing the tile_images vector when filling it. This mitigates that by reserving a generous amount of space ahead of time, and also keeps track of the global maximum number of images per tile encountered so far.

These three optimizations reduce the total render time of a simple map by ~15% on my machine.

I've also replaced boost::container::vector with std::vector just to shave off an #include.

DaMatrix avatar Jul 03 '25 16:07 DaMatrix