Skip to content

Commit f3a5b42

Browse files
arjo129mergify[bot]
authored andcommitted
Improve load times by skipping serialization of entities when unecessary. (#2596)
* A hack to greatly improve load times 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 <arjoc@intrinsic.ai> * Remove magic word Signed-off-by: Arjo Chakravarty <arjoc@intrinsic.ai> * Send empty string instead of using sentinel value. Signed-off-by: Arjo Chakravarty <arjoc@intrinsic.ai> * Style Signed-off-by: Arjo Chakravarty <arjoc@intrinsic.ai> * fix custom sensor system example build (#2649) Signed-off-by: Ian Chen <ichen@openrobotics.org> * remove stray change Signed-off-by: Arjo Chakravarty <arjoc@intrinsic.ai> --------- Signed-off-by: Arjo Chakravarty <arjoc@intrinsic.ai> Signed-off-by: Ian Chen <ichen@openrobotics.org> Co-authored-by: Ian Chen <ichen@openrobotics.org> (cherry picked from commit 1a88131) # Conflicts: # include/gz/sim/components/Model.hh
1 parent a7ea4ac commit f3a5b42

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

include/gz/sim/components/Model.hh

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,18 @@ namespace serializers
7575
}
7676
}
7777

78-
_out << "<?xml version=\"1.0\" ?>"
79-
<< "<sdf version='" << SDF_PROTOCOL_VERSION << "'>"
80-
<< (skip ? std::string() : modelElem->ToString(""))
81-
<< "</sdf>";
78+
if (!skip)
79+
{
80+
_out << "<?xml version=\"1.0\" ?>"
81+
<< "<sdf version='" << SDF_PROTOCOL_VERSION << "'>"
82+
<< modelElem->ToString("")
83+
<< "</sdf>";
84+
85+
}
86+
else
87+
{
88+
_out << "";
89+
}
8290
return _out;
8391
}
8492

@@ -89,13 +97,22 @@ namespace serializers
8997
public: static std::istream &Deserialize(std::istream &_in,
9098
sdf::Model &_model)
9199
{
92-
sdf::Root root;
93100
std::string sdf(std::istreambuf_iterator<char>(_in), {});
101+
if (sdf.empty())
102+
{
103+
return _in;
104+
}
94105

106+
// Its super expensive to create an SDFElement for some reason
107+
sdf::Root root;
95108
sdf::Errors errors = root.LoadSdfString(sdf);
96109
if (!root.Model())
97110
{
111+
<<<<<<< HEAD
98112
ignwarn << "Unable to deserialize sdf::Model" << std::endl;
113+
=======
114+
gzwarn << "Unable to deserialize sdf::Model " << sdf<< std::endl;
115+
>>>>>>> 1a881310c (Improve load times by skipping serialization of entities when unecessary. (#2596))
99116
return _in;
100117
}
101118

0 commit comments

Comments
 (0)