Skip to content

Conversation

@Alich13
Copy link
Contributor

@Alich13 Alich13 commented Dec 20, 2025

  • use std::vector instead of std:set
  • use a transparent lookup
  • Lightweight lookup helper - avoids constructing objects for map lookups

The fixes above ensure cache locality and reduce mem fragmentation risks.

TL;DR: Cache locality means accessing memory that's physically close together.

  • std::vector: All elements next to each other → CPU loads many at once
  • std::set: Elements scattered in tree nodes → CPU must fetch each separately

Memory fragmentation might happen when we have free memory, but it's scattered in small chunks that can't be used efficiently, which is the case when using std::set.

Oversimplified illustration of mem fragmentation

# std::set allocations
Free memory, but fragmented (can't allocate 5 contiguous blocks): 
[Used][Free][Used][Free][Free][Used][Free][Used][Free]
# std::vector allocations
Free memory, contiguous (can easily allocate):
[Used][Used][Used][Free][Free][Free][Free][Free][Free]

Also, std::vector allocates 4 bytes per element , 4 to 5 times less than std::set which allocates ~24-32 bytes per node (pointers for left child, right child, parent, plus color bit for red-black tree)

* use a  transparent lookup
* Lightweight lookup helper - avoids constructing objects for map lookups

pair<Info3PointBlock, bool> getInfo3Point(
int X, int Y, int Z, const vector<int>& ui) {
auto it = i3_map_.find(Info3PointKey(X, Y, Z, ui));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid constructing these tmp objects each time we look up in the cache and use a transparent lookup

@Alich13 Alich13 requested a review from franck-simon December 20, 2025 22:58
@Alich13 Alich13 marked this pull request as ready for review December 20, 2025 23:44
@Alich13 Alich13 merged commit 1d77473 into master Jan 29, 2026
5 checks passed
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