Skip to content

Conversation

@DaMatrix
Copy link

@DaMatrix DaMatrix commented Jul 3, 2025

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 added 4 commits July 3, 2025 14:23
This improves overall render performance by roughly 10%.

This has two main differences:
- We make separate calls to std::sort for each comparator type, to avoid dynamic dispatch at runtime and allow the comparator to be inlined
- We only sort pointers to the tiles instead of tiles themselves. This means substantially less data has to be moved around, as each step in the sorting algorithm only has to swap two pointers instead of repeatedly move-constructing TileImage instances, and is responsible for most of the performance improvement.
…images vector

this reduces how often the vector's storage needs to be grown during rendering, which is a pretty expensive process
@miclav
Copy link
Owner

miclav commented Jul 7, 2025

Hi
Thanks for the pull request. I'll have a look in the coming days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants