Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ManagedContainers - Change underlying data structure to unordered map #1423

Merged
merged 3 commits into from
Aug 4, 2021

Conversation

jturner65
Copy link
Contributor

Motivation and Context

This PR changes the underlying data structure for the Managed Containers from std::map to std::unordered_map, for better performance with containers holding many elements.

The only downside to this process is that formerly, any string-based query of the managed container would return results in sorted order. This PR will sort the results from such a query as default behavior, which can also be overridden on demand if sorting is not required. Since generally the results set is small (where the query is matching a substring of the handles of objects held in the map), the overhead for this sort will also generally be small.

How Has This Been Tested

C++ and python tests

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have completed my CLA (see CONTRIBUTING)
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Aug 4, 2021
@jturner65 jturner65 requested a review from aclegg3 August 4, 2021 21:15
Copy link
Contributor

@Skylion007 Skylion007 left a comment

Choose a reason for hiding this comment

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

Thanks, was considering making this change for a while as well, but never got around to doing it.

@jturner65
Copy link
Contributor Author

jturner65 commented Aug 4, 2021

Thanks, was considering making this change for a while as well, but never got around to doing it.

Had to consider it a bit, since the unordered map is slightly larger for small containers (less than 14 elements from what I have seen), but we don't have a lot of small containers so this isn't really a concern. And apparently, running some tests on my machine, accessing the unordered map will be around 2-3x faster, which to me excuses the overhead of sorting key search results.

@Skylion007
Copy link
Contributor

If you really want to take this to the next level, there are some better unordered_map implementations than the STL.

@jturner65 jturner65 merged commit 8669883 into facebookresearch:master Aug 4, 2021
@jturner65 jturner65 deleted the MM_MapToUnordered branch August 4, 2021 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants