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::reserve in Element::Clone #1480

Draft
wants to merge 1 commit into
base: sdf15
Choose a base branch
from

Conversation

scpeters
Copy link
Member

@scpeters scpeters commented Sep 9, 2024

🦟 Bug fix

Part of #1478

Summary

The performance of Element::Clone is poor, as noted in #1478. This is a small change to attempt to improve memory allocation.

There are several for-loops in Element::Clone that call std::vector::push_back, and since the vector size is known in advance, use std::vector::reserve to avoid multiple vector resizes.

I ran the unit tests with this change, and I didn't observe any noticeable speed-up.

Checklist

  • Signed all commits for DCO
  • Added tests
  • 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.

There are several for-loops in Element::Clone that call
std::vector::push_back, and since the vector size is
known in advance, use std::vector::reserve to avoid
multiple vector resizes.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏛️ ionic Gazebo Ionic
Projects
Status: Inbox
Development

Successfully merging this pull request may close these issues.

1 participant