-
Notifications
You must be signed in to change notification settings - Fork 205
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
Set error status when duplicate markers are in the same MarkerArray #891
Set error status when duplicate markers are in the same MarkerArray #891
Conversation
nice! one concern though is performance - there any simple performance tests that can be done to check that this processing doesn't blow compute budget for 30 FPS when using something like 1000 markers? Also, is there perhaps a more efficient way to bookkeep? e.g. std::set<PairType> existing;
bool found_duplicates = false;
for (marker : markers) {
addMessage(copy_of(marker));
if (!found_duplicates) {
PairType pair{marker.ns, marker.id};
const bool is_new = existing.insert(pair).second;
found_duplicates = !is_new;
}
}
if (found_duplicates) {
warn();
} |
I don't think it changes behavior, at least that was my intent since I'd like to backport this. |
gotcha, missed that. and yeah, your setup looks great, but still, perhaps good to use something with comparison time less than also, is necessary to have one loop with the full critical section, or might it be best to process message / check for duplicates before obtaining lock? soz for asking dumb questions, just want to check |
46382a0 adds a temporary benchmark looking at how id's affect performance.
The best case of the current method (called vector_of_pairs) adds just a few percent of overhead, but the worst case is about 43 times slower than not checking for duplicates at 10,000 elements. The implementation using an |
Thanks! Given that (10, 10000) markers can take:
I think |
(as an aside, mayhaps |
66aa859
to
3662e20
Compare
I added some more benchmarks and switched to
I didn't try this one because it requires implementing a hash function for the pair. |
Yup, those results look like a convincing case for a reasonable trade-off between best- and worse-case using set + id-first, thanks! |
rviz_default_plugins/src/rviz_default_plugins/displays/marker/marker_common.cpp
Outdated
Show resolved
Hide resolved
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
3662e20
to
4e01043
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved from my perspective. Any chance there's a maintainer available to review?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, one comment below; take it or leave it.
pair_type pair(marker.id, marker.ns); | ||
found_duplicate = !unique_markers.insert(pair).second; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using emplace
if performance is a concern. I'm not sure if moves the needle on your benchmark though:
pair_type pair(marker.id, marker.ns); | |
found_duplicate = !unique_markers.insert(pair).second; | |
found_duplicate = !unique_markers.emplace(marker.id, marker.ns).second; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried out in a benchmark, but I can't see a difference between emplace
and insert
within the noise.
One of the runs
56: 2022-09-02T13:58:15-07:00
56: Running /home/osrf/ws/ros2/build/rviz_default_plugins/bm891
56: Run on (24 X 4950.19 MHz CPU s)
56: CPU Caches:
56: L1 Data 32 KiB (x12)
56: L1 Instruction 32 KiB (x12)
56: L2 Unified 512 KiB (x12)
56: L3 Unified 32768 KiB (x2)
56: Load Average: 1.67, 2.49, 1.99
56: ***WARNING*** CPU scaling is enabled, the benchmark real time measurements may be noisy and will incur extra overhead.
56: ------------------------------------------------------------------------------------------------------------
56: Benchmark Time CPU Iterations
56: ------------------------------------------------------------------------------------------------------------
56: no_check_10 494 ns 494 ns 1390157
56: no_check_100 5035 ns 5034 ns 139124
56: no_check_1000 52140 ns 52134 ns 13403
56: no_check_10000 522287 ns 522195 ns 1330
56: increasing_ids__vector_of_pairs__10 540 ns 540 ns 1293151
56: increasing_ids__vector_of_pairs__100 5126 ns 5124 ns 136431
56: increasing_ids__vector_of_pairs__1000 53451 ns 53444 ns 13273
56: increasing_ids__vector_of_pairs__10000 526744 ns 526664 ns 1291
56: decreasing_ids__vector_of_pairs__10 552 ns 552 ns 1266562
56: decreasing_ids__vector_of_pairs__100 7073 ns 7072 ns 97768
56: decreasing_ids__vector_of_pairs__1000 187947 ns 187922 ns 3712
56: decreasing_ids__vector_of_pairs__10000 11610110 ns 11608107 ns 60
56: increasing_ids__set_insertion__10 730 ns 730 ns 954514
56: increasing_ids__set_insertion__100 10345 ns 10341 ns 67748
56: increasing_ids__set_insertion__1000 121661 ns 121645 ns 5752
56: increasing_ids__set_insertion__10000 1360934 ns 1360740 ns 516
56: decreasing_ids__set_insertion__10 738 ns 738 ns 947607
56: decreasing_ids__set_insertion__100 9665 ns 9664 ns 72394
56: decreasing_ids__set_insertion__1000 120601 ns 120586 ns 5779
56: decreasing_ids__set_insertion__10000 1340419 ns 1340184 ns 526
56: increasing_ids__set_insertion_id_first__10 708 ns 708 ns 987930
56: increasing_ids__set_insertion_id_first__100 8838 ns 8837 ns 79525
56: increasing_ids__set_insertion_id_first__1000 105766 ns 105751 ns 6617
56: increasing_ids__set_insertion_id_first__10000 1141860 ns 1141685 ns 615
56: decreasing_ids__set_insertion_id_first__10 724 ns 724 ns 967446
56: decreasing_ids__set_insertion_id_first__100 8674 ns 8673 ns 80745
56: decreasing_ids__set_insertion_id_first__1000 105557 ns 105542 ns 6615
56: decreasing_ids__set_insertion_id_first__10000 1128819 ns 1128658 ns 631
56: increasing_ids__set_insertion_id_first_always_lock__10 752 ns 752 ns 930742
56: increasing_ids__set_insertion_id_first_always_lock__100 9304 ns 9303 ns 75296
56: increasing_ids__set_insertion_id_first_always_lock__1000 109530 ns 109515 ns 6393
56: increasing_ids__set_insertion_id_first_always_lock__10000 1175368 ns 1175185 ns 596
56: decreasing_ids__set_insertion_id_first_always_lock__10 722 ns 722 ns 968217
56: decreasing_ids__set_insertion_id_first_always_lock__100 9042 ns 9041 ns 77217
56: decreasing_ids__set_insertion_id_first_always_lock__1000 108964 ns 108949 ns 6395
56: decreasing_ids__set_insertion_id_first_always_lock__10000 1185452 ns 1185020 ns 598
56: increasing_ids__set_insertion_id_first_always_lock_emplace__10 757 ns 757 ns 921752
56: increasing_ids__set_insertion_id_first_always_lock_emplace__100 9250 ns 9249 ns 75718
56: increasing_ids__set_insertion_id_first_always_lock_emplace__1000 109513 ns 109499 ns 6318
56: increasing_ids__set_insertion_id_first_always_lock_emplace__10000 1190149 ns 1189968 ns 591
56: decreasing_ids__set_insertion_id_first_always_lock_emplace__10 759 ns 759 ns 920237
56: decreasing_ids__set_insertion_id_first_always_lock_emplace__100 9133 ns 9132 ns 76482
56: decreasing_ids__set_insertion_id_first_always_lock_emplace__1000 109207 ns 109191 ns 6436
56: decreasing_ids__set_insertion_id_first_always_lock_emplace__10000 1139710 ns 1139538 ns 613
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm, aside from my comment about providing more debug info.
display_->setStatusStd( | ||
rviz_common::properties::StatusProperty::Error, | ||
kDuplicateStatus, | ||
"Multiple Markers in the same MarkerArray message had the same namespace and id"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this enough information for someone to debug this problem?
Maybe it should include how many are duplicates and/or which namespace/id are offending.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made the error message include the first offending namespace and id in ba16715
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> More benchmarks Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
This reverts commit 8aeea4c. Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
4e01043
to
9bc888b
Compare
CMake warning on windows is unrelated to this PR |
@Mergifyio backport humble galactic foxy |
…891) * Set error status when duplicate markers are in the same MarkerArray Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Use std::set with id before ns Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Lock/Unlock for every message Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Output first offending namespace and id Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Add benchmark Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> More benchmarks Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Revert "Add benchmark" This reverts commit 8aeea4c. Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> (cherry picked from commit e069694)
…891) * Set error status when duplicate markers are in the same MarkerArray Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Use std::set with id before ns Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Lock/Unlock for every message Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Output first offending namespace and id Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Add benchmark Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> More benchmarks Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Revert "Add benchmark" This reverts commit 8aeea4c. Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> (cherry picked from commit e069694)
✅ Backports have been created
|
…891) * Set error status when duplicate markers are in the same MarkerArray Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Use std::set with id before ns Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Lock/Unlock for every message Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Output first offending namespace and id Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Add benchmark Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> More benchmarks Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Revert "Add benchmark" This reverts commit 8aeea4c. Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> (cherry picked from commit e069694)
…891) (#901) * Set error status when duplicate markers are in the same MarkerArray Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Use std::set with id before ns Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Lock/Unlock for every message Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Output first offending namespace and id Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Add benchmark Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> More benchmarks Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Revert "Add benchmark" This reverts commit 8aeea4c. Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> (cherry picked from commit e069694) Co-authored-by: Shane Loretz <sloretz@osrfoundation.org>
…891) (#899) * Set error status when duplicate markers are in the same MarkerArray Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Use std::set with id before ns Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Lock/Unlock for every message Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Output first offending namespace and id Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Add benchmark Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> More benchmarks Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Revert "Add benchmark" This reverts commit 8aeea4c. Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> (cherry picked from commit e069694) Co-authored-by: Shane Loretz <sloretz@osrfoundation.org>
…891) (#900) * Set error status when duplicate markers are in the same MarkerArray Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Use std::set with id before ns Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Lock/Unlock for every message Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Output first offending namespace and id Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Add benchmark Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> More benchmarks Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * Revert "Add benchmark" This reverts commit 8aeea4c. Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> (cherry picked from commit e069694) Co-authored-by: Shane Loretz <sloretz@osrfoundation.org>
This pull request adds an errors status to the
MarkerArray
display when a singleMarkerArray
message with duplicate markers is received. This can happen when the publisher author forgot to setid
orns
. Assuming all theMarker
messages have the same action (add/modify), it results in only the last marker being displayed.Script for checking