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

Use std::vector instead of std::map in BaseStorage #831

Merged
merged 2 commits into from
Mar 14, 2023

Conversation

nkoenig
Copy link
Contributor

@nkoenig nkoenig commented Mar 9, 2023

🎉 New feature

Summary

Most of the time the store std::map inside BaseStorage is iterated over, which is not as efficient as a std::vector.

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

Signed-off-by: Nate Koenig <natekoenig@gmail.com>
@nkoenig nkoenig requested a review from iche033 as a code owner March 9, 2023 16:32
@osrf-triage osrf-triage added this to Inbox in Core development Mar 9, 2023
@github-actions github-actions bot added the 🎵 harmonic Gazebo Harmonic label Mar 9, 2023
include/gz/rendering/base/BaseStorage.hh Show resolved Hide resolved
{
return this->store.end();
}
return ConstIterByIndex(idx->second);
Copy link
Contributor

Choose a reason for hiding this comment

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

I see we're returning iterators. If the iterators are being stored somewhere, we need to be careful since insertion to the std::vector might invalidate it. This was not the case for std::map, so we might be introducing subtle bugs here.

Copy link
Contributor

@iche033 iche033 Mar 10, 2023

Choose a reason for hiding this comment

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

Since the original implementation was based on a map, it makes sense to keep iters and pass them around. Now that we're changing to vector, I think we don't need to be doing this as much. The only place that use these IterByName functions internally is ContainsName, which can by re-implemented easily.

So how about we deprecate ConstIterByName / IterByName functions, update doxygen comment for these 2 APIs to warn users not to keep a handle to the iterator as it may change, and add a note to migration guide?

If that sounds good, I can help with this in a follow-up PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok I created a PR: #832

I didn't deprecate the functions. Instead I added doc with a note that iterators can change / become invalid. I also updated migration guide.

@iche033
Copy link
Contributor

iche033 commented Mar 10, 2023

UNIT_Scene_TEST is failing, could be related

@iche033
Copy link
Contributor

iche033 commented Mar 10, 2023

UNIT_Scene_TEST is failing, could be related

fixed in #832

@azeey azeey moved this from Inbox to In review in Core development Mar 13, 2023
* add doc and fix test

Signed-off-by: Ian Chen <ichen@openrobotics.org>
@codecov
Copy link

codecov bot commented Mar 13, 2023

Codecov Report

Merging #831 (47d44bf) into main (073ad9d) will increase coverage by 0.02%.
The diff coverage is 92.85%.

❗ Current head 47d44bf differs from pull request most recent head 54089f0. Consider uploading reports for the commit 54089f0 to get more accurate results

@@            Coverage Diff             @@
##             main     #831      +/-   ##
==========================================
+ Coverage   75.29%   75.31%   +0.02%     
==========================================
  Files         177      177              
  Lines       16020    16027       +7     
==========================================
+ Hits        12062    12071       +9     
+ Misses       3958     3956       -2     
Impacted Files Coverage Δ
include/gz/rendering/base/BaseVisual.hh 71.64% <66.66%> (+0.28%) ⬆️
include/gz/rendering/base/BaseStorage.hh 68.68% <100.00%> (+1.02%) ⬆️
ogre2/src/Ogre2Visual.cc 85.40% <100.00%> (-0.11%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@nkoenig
Copy link
Contributor Author

nkoenig commented Mar 14, 2023

@azeey , are you okay with this PR?

@nkoenig nkoenig requested a review from azeey March 14, 2023 17:43
@azeey
Copy link
Contributor

azeey commented Mar 14, 2023

If Ian has approved it, it's good with me. I was just quickly looking through and noticed iterators being returned and alarm bells went off in my head.

@nkoenig nkoenig merged commit bc40120 into main Mar 14, 2023
Core development automation moved this from In review to Done Mar 14, 2023
@nkoenig nkoenig deleted the improve_base_storage_performance branch March 14, 2023 18:20
@iche033 iche033 mentioned this pull request Aug 31, 2023
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎵 harmonic Gazebo Harmonic
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants