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

Improve load times by skipping serialization of entities when unecessary. #2596

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
17 changes: 15 additions & 2 deletions include/gz/sim/components/Model.hh
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,18 @@ namespace serializers
}
}

if (!skip)
{
_out << "<?xml version=\"1.0\" ?>"
<< "<sdf version='" << SDF_PROTOCOL_VERSION << "'>"
<< (skip ? std::string() : modelElem->ToString(""))
<< "</sdf>";
arjo129 marked this conversation as resolved.
Show resolved Hide resolved

}
else
{
_out << "";
}
return _out;
}

Expand All @@ -89,13 +97,18 @@ namespace serializers
public: static std::istream &Deserialize(std::istream &_in,
sdf::Model &_model)
{
sdf::Root root;
std::string sdf(std::istreambuf_iterator<char>(_in), {});
if (sdf.empty())
{
return _in;
}

// Its super expensive to create an SDFElement for some reason
sdf::Root root;
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
Loading