-
Notifications
You must be signed in to change notification settings - Fork 317
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
[SofaKernel] Switch from map_ptr_stable_compare to std::unordered_map #2047
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ci-build][with-all-tests] |
Test the behavior of NarrowPhaseDetection regarding its DetectionOutputMap
See #2053 for real-life consequences of the choice of the map. |
I am not sure of the consequence to change the maps, but if :
I am ok with that. |
Looks good to me. I looked quickly at the "delete from within a loop" thing, and I can't see where it could fail. So 👍 for this change on my side. |
alxbilger
added a commit
to alxbilger/sofa
that referenced
this pull request
May 7, 2021
For now, map_ptr_stable_compare is preferred over unordered_map, as it allows reproducible contact response. However, unordered_map is still a lot faster.
This was referenced May 7, 2021
fredroy
pushed a commit
that referenced
this pull request
May 7, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
issue: discussion
Open topic of discussion
pr: experimental
Demonstrate an experimental feature
pr: status ready
Approved a pull-request, ready to be squashed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a discussion about the need for
sofa::helper::map_ptr_stable_compare
, inNarrowPhaseDetection
, but also in Sofa in general (it is also used inDefaultContactManager
).According to benchmarks comparing 3 different types of maps,
sofa::helper::map_ptr_stable_compare
is several orders of magnitude slower thanstd::map
andstd::unordered_map
.std::unordered_map
std::map
sofa::helper::map_ptr_stable_compare
The benchmarks were performed using https://github.com/alxbilger/SofaBenchmark.
BM_NarrowPhaseDetection_getDetectionOutputs/n
corresponds to a map containingn^2
pairs ofCollisionModel*
.Discussion
It is undeniable that
std::map
andstd::unordered_map
are faster thansofa::helper::map_ptr_stable_compare
. However, I don't know how crucial it is to have this kind of map with a dedicated comparator. Is this feature necessary? If not, I am in favour of usingstd::unordered_map
whereversofa::helper::map_ptr_stable_compare
is used, for performances reasons.Overall, we won't get a huge gain of fps, but still it has an impact on the peformances of
NarrowPhaseDetection
. Initially, I wondered whyNarrowPhaseDetection
took so much time for so simple instructions.By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).
Reviewers will merge this pull-request only if