Skip to content

Optimize load time and memory consumption by reusing element descriptions (backport #1589)#1673

Open
mergify[bot] wants to merge 1 commit into
mainfrom
mergify/bp/main/pr-1589
Open

Optimize load time and memory consumption by reusing element descriptions (backport #1589)#1673
mergify[bot] wants to merge 1 commit into
mainfrom
mergify/bp/main/pr-1589

Conversation

@mergify

@mergify mergify Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

🦟 Bug fix

Toward gazebosim/jetty_demo#3

Summary

As far as I can tell, element descriptions are not mutated, so there is no reason to clone them. But I'm not 100% sure if this has unintended consequences.

I created a small test where a large sdf is loaded to show the before and after memory consumption results:
Before

$ time build/sdf_memory 3k_shapes.sdf
Successfully loaded file
8647.16MB
build/sdf_memory 3k_shapes.sdf  6.77s user 3.13s system 99% cpu 9.904 total

After

$ time build/sdf_memory 3k_shapes.sdf
Successfully loaded file
289.069MB
build/sdf_memory 3k_shapes.sdf  0.40s user 0.19s system 97% cpu 0.611 total

This is a significant speedup and reduction in memory usage, so it would be worth figuring out if we can truly do this without any negative consequences.

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
  • Was GenAI used to generate this PR? If so, make sure to add "Generated-by" to your commits. (See this policy for more info.)

Generated-by: Remove this if GenAI was not used.

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


This is an automatic backport of pull request #1589 done by [Mergify](https://mergify.com).

…ions (#1589)

In most usages of `GetElementDescription`, the returned `sdf::ElementPtr` is not mutated, thus it is possible to implement a copy-on-write mechanism to avoid unnecessary clones of element descriptions. This PR removes clones of element description during the loading of an SDFormat file and introduces APIs to get immutable element descriptions. It also provides mutable element descriptions which clone the element description when called.

* Do not clone element descriptions
* Add MutableElementDescription and deprecate GetElementDescription
* Add tests
* Narrower use of GZ_UTILS_WARN_* macros
* Reword comments, Migration guide
* Remove duplicate line in python test
* Add / adjust //// lines

Signed-off-by: Steve Peters <scpeters@openrobotics.org>

---------

Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
Signed-off-by: Steve Peters <scpeters@openrobotics.org>
Co-authored-by: Steve Peters <scpeters@openrobotics.org>
(cherry picked from commit db6bdbb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Inbox

Development

Successfully merging this pull request may close these issues.

1 participant