Skip to content

Commit

Permalink
A hack to greatly improve load times
Browse files Browse the repository at this point in the history
I was investigating
gazebosim/gazebo_test_cases#1576 , in my
investigation it came to my notice that `sdf::Element` takes forever to
destroy (We should open a ticket somewhere about this). If we are
skipping serialization we might as well not create and destroy an
SDF Element. This hack greatly speeds up the load time for gazebo.

Signed-off-by: Arjo Chakravarty <[email protected]>
  • Loading branch information
arjo129 committed Sep 5, 2024
1 parent a20bf25 commit 3b1ca48
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion include/gz/sim/components/Model.hh
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ namespace serializers
}
}

// Why bother even sending this. Wouldn't a blank string work?
_out << "<?xml version=\"1.0\" ?>"
<< "<sdf version='" << SDF_PROTOCOL_VERSION << "'>"
<< (skip ? std::string() : modelElem->ToString(""))
Expand All @@ -91,11 +92,17 @@ namespace serializers
{
sdf::Root root;
std::string sdf(std::istreambuf_iterator<char>(_in), {});
if (sdf.find("model") == std::string::npos)
{
gzwarn << "No model was sent\n";
return _in;
}
// Its super expensive to create an SDFElement for some reason

sdf::Errors errors = root.LoadSdfString(sdf);
if (!root.Model())
{
gzwarn << "Unable to deserialize sdf::Model" << std::endl;
gzwarn << "Unable to deserialize sdf::Model " << sdf<< std::endl;
return _in;
}

Expand Down

0 comments on commit 3b1ca48

Please sign in to comment.