Skip to content

Introduce a cache to improve performance of construction of SDFormat (backport #1610)#1614

Merged
azeey merged 1 commit intosdf14from
mergify/bp/sdf14/pr-1610
Jan 2, 2026
Merged

Introduce a cache to improve performance of construction of SDFormat (backport #1610)#1614
azeey merged 1 commit intosdf14from
mergify/bp/sdf14/pr-1610

Conversation

@mergify
Copy link
Copy Markdown
Contributor

@mergify mergify bot commented Jan 2, 2026

🦟 Bug fix

Fixes #1478

Summary

This commit should reduce load times significantly as it caches the first parse of the spec so that it does not need to be reparsed during construction through static initiallization of a cache.

On my m4 macbook air this reduces the following benchmark:

#include <sdf/Model.hh>
#include <sdf/Root.hh>

void deserialize()
{
    std::string sdf = "<?xml version=\"1.0\" ?><sdf version='1.6'></sdf>";
    sdf::Root root;
    sdf::Errors errors = root.LoadSdfString(sdf);
    if (!root.Model())
    {
        return;
    }
    sdf::Model _model = *root.Model();
    return;
}

int main(int argc, char **argv)
{
    std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
    for (int i = 0; i < 100; i++)
    deserialize();
    std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();

    std::cout << "Whole function call took: " <<
        std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count()
        << "[µs]" << std::endl;
}

from running for 300000µs to 3000µs.

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.)

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 #1610 done by [Mergify](https://mergify.com).

…1610)

Reduces load times significantly as it caches the first parse of the spec so that it does not need to be reparsed during construction through static initiallization of a cache.

---------

Signed-off-by: Arjo Chakravarty <arjo@openrobotics.org>
Signed-off-by: Arjo Chakravarty <arjo129@gmail.com>
Co-authored-by: Addisu Z. Taddese <addisu@openrobotics.org>
(cherry picked from commit 403d96a)
@github-project-automation github-project-automation bot moved this from Inbox to In review in Core development Jan 2, 2026
@azeey azeey merged commit a298d01 into sdf14 Jan 2, 2026
14 checks passed
@azeey azeey deleted the mergify/bp/sdf14/pr-1610 branch January 2, 2026 21:16
@github-project-automation github-project-automation bot moved this from In review to Done in Core development Jan 2, 2026
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.

2 participants