Skip to content

Foundation Classes - Align FlatMap/FlatDataMap lookup path and update usage notes - #1108

Merged
dpasukhi merged 1 commit into
Open-Cascade-SAS:IRfrom
dpasukhi:flat_map_improvements
Feb 23, 2026
Merged

dpasukhi merged 1 commit into
Open-Cascade-SAS:IRfrom
dpasukhi:flat_map_improvements

Conversation

@dpasukhi

Copy link
Copy Markdown
Member
  • Simplify findSlotIndex() in NCollection_FlatMap and NCollection_FlatDataMap to probe until empty slot or key match.
  • Remove lookup early-exit based on probe distance to keep lookup behavior consistent between both flat containers.
  • Reorder NCollection_FlatDataMap::Slot members to keep hash/probe metadata before key/value storage.
  • Refresh class-level Doxygen comments with practical usage guidance and relative notes vs NCollection_Map / NCollection_DataMap.

… usage notes

- Simplify `findSlotIndex()` in `NCollection_FlatMap` and `NCollection_FlatDataMap` to probe until empty slot or key match.
- Remove lookup early-exit based on probe distance to keep lookup behavior consistent between both flat containers.
- Reorder `NCollection_FlatDataMap::Slot` members to keep hash/probe metadata before key/value storage.
- Refresh class-level Doxygen comments with practical usage guidance and relative notes vs `NCollection_Map` / `NCollection_DataMap`.
@dpasukhi
dpasukhi requested a review from Copilot February 22, 2026 20:21
@dpasukhi dpasukhi self-assigned this Feb 22, 2026
@dpasukhi dpasukhi added the 1. Foundation Classes Containers, system calls wrappers, smart pointers and other low level of OCCT code label Feb 22, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This pull request simplifies the lookup path in NCollection_FlatMap and NCollection_FlatDataMap by removing the Robin Hood early-exit optimization and updates the class-level documentation with clearer usage guidance. The changes align the lookup behavior between both flat containers and improve documentation clarity.

Changes:

  • Simplified findSlotIndex() to probe until finding an empty slot or key match, removing the early-exit optimization based on probe distance comparison
  • Reordered NCollection_FlatDataMap::Slot struct members to place hash/probe metadata before key/value storage for better cache locality
  • Enhanced Doxygen documentation with practical usage patterns, performance characteristics relative to NCollection_Map/NCollection_DataMap, and implementation notes

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
NCollection_FlatMap.hxx Simplified lookup loop and updated documentation with usage patterns and relative performance notes
NCollection_FlatDataMap.hxx Simplified lookup loop, reordered Slot members, and updated documentation with usage patterns and relative performance notes

size_t aIndex = aHash & aMask;

while (aProbe < aMaxProbe)
while (true)

Copilot AI Feb 22, 2026

Copy link

Choose a reason for hiding this comment

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

Removing the Robin Hood early-exit optimization (probe distance check) will significantly degrade lookup performance in pathological cases with high collision rates. In the worst case (e.g., with ConstantHasher that returns the same hash for all keys), a failed lookup must now scan through all occupied slots until finding an empty one, rather than exiting early when encountering a slot with lower probe distance. This could mean scanning hundreds of consecutive slots instead of just a few.

While the load factor guarantee ensures the loop will terminate, the performance degradation is measurable. Consider keeping the early-exit optimization for better performance characteristics, especially since Robin Hood hashing is designed to maintain the invariant that enables this optimization.

Copilot uses AI. Check for mistakes.
Comment on lines 96 to +100
size_t myHash; //!< Cached hash code
//! Distance from ideal bucket plus one; 0 means Empty, otherwise Used.
size_t myProbeDistancePlus1;
alignas(TheKeyType) char myKeyStorage[sizeof(TheKeyType)];
alignas(TheItemType) char myItemStorage[sizeof(TheItemType)];

Copilot AI Feb 22, 2026

Copy link

Choose a reason for hiding this comment

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

The reordering of Slot struct members to place hash/probe metadata before key/value storage is a good optimization. This improves cache locality during lookups since the hash and probe distance are checked before accessing the key. However, verify that this doesn't introduce unexpected padding that increases the overall Slot size. Consider documenting the rationale for this ordering in a comment.

Copilot uses AI. Check for mistakes.
size_t aIndex = aHash & aMask;

while (aProbe < aMaxProbe)
while (true)

Copilot AI Feb 22, 2026

Copy link

Choose a reason for hiding this comment

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

Removing the Robin Hood early-exit optimization (probe distance check) will significantly degrade lookup performance in pathological cases with high collision rates. In the worst case (e.g., with ConstantHasher that returns the same hash for all keys), a failed lookup must now scan through all occupied slots until finding an empty one, rather than exiting early when encountering a slot with lower probe distance. This could mean scanning hundreds of consecutive slots instead of just a few.

While the load factor guarantee ensures the loop will terminate, the performance degradation is measurable. Consider keeping the early-exit optimization for better performance characteristics, especially since Robin Hood hashing is designed to maintain the invariant that enables this optimization.

Copilot uses AI. Check for mistakes.
@dpasukhi
dpasukhi merged commit 8430a53 into Open-Cascade-SAS:IR Feb 23, 2026
22 checks passed
@dpasukhi
dpasukhi deleted the flat_map_improvements branch February 23, 2026 09:28
@github-project-automation github-project-automation Bot moved this from Todo to Done in Maintenance Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1. Foundation Classes Containers, system calls wrappers, smart pointers and other low level of OCCT code

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants