Optimize load time and memory consumption by reusing element descriptions (backport #1589)#1673
Open
mergify[bot] wants to merge 1 commit into
Open
Optimize load time and memory consumption by reusing element descriptions (backport #1589)#1673mergify[bot] wants to merge 1 commit into
mergify[bot] wants to merge 1 commit into
Conversation
…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)
9 tasks
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
🦟 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 totalAfter
$ 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 totalThis 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
codecheckpassed (See contributing)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-byandGenerated-bymessages.This is an automatic backport of pull request #1589 done by [Mergify](https://mergify.com).