From f3a5b42c6701cd314e3962a926fb67b9add9e999 Mon Sep 17 00:00:00 2001 From: Arjo Chakravarty Date: Tue, 19 Nov 2024 04:46:50 +0800 Subject: [PATCH 1/2] Improve load times by skipping serialization of entities when unecessary. (#2596) * A hack to greatly improve load times I was investigating https://github.com/gazebosim/gazebo_test_cases/issues/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 * Remove magic word Signed-off-by: Arjo Chakravarty * Send empty string instead of using sentinel value. Signed-off-by: Arjo Chakravarty * Style Signed-off-by: Arjo Chakravarty * fix custom sensor system example build (#2649) Signed-off-by: Ian Chen * remove stray change Signed-off-by: Arjo Chakravarty --------- Signed-off-by: Arjo Chakravarty Signed-off-by: Ian Chen Co-authored-by: Ian Chen (cherry picked from commit 1a881310cfe2e1c97bdb7d606cf973eebc17a6c1) # Conflicts: # include/gz/sim/components/Model.hh --- include/gz/sim/components/Model.hh | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/include/gz/sim/components/Model.hh b/include/gz/sim/components/Model.hh index e9aa8996df..af8b4376c4 100644 --- a/include/gz/sim/components/Model.hh +++ b/include/gz/sim/components/Model.hh @@ -75,10 +75,18 @@ namespace serializers } } - _out << "" - << "" - << (skip ? std::string() : modelElem->ToString("")) - << ""; + if (!skip) + { + _out << "" + << "" + << modelElem->ToString("") + << ""; + + } + else + { + _out << ""; + } return _out; } @@ -89,13 +97,22 @@ namespace serializers public: static std::istream &Deserialize(std::istream &_in, sdf::Model &_model) { - sdf::Root root; std::string sdf(std::istreambuf_iterator(_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()) { +<<<<<<< HEAD ignwarn << "Unable to deserialize sdf::Model" << std::endl; +======= + gzwarn << "Unable to deserialize sdf::Model " << sdf<< std::endl; +>>>>>>> 1a881310c (Improve load times by skipping serialization of entities when unecessary. (#2596)) return _in; } From ceba568f495c33a98a0f740627bdc9d322ca8946 Mon Sep 17 00:00:00 2001 From: Arjo Chakravarty Date: Tue, 19 Nov 2024 12:04:51 +0800 Subject: [PATCH 2/2] gzwarn -> ignwarn Signed-off-by: Arjo Chakravarty --- include/gz/sim/components/Model.hh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/include/gz/sim/components/Model.hh b/include/gz/sim/components/Model.hh index af8b4376c4..6b23c7499e 100644 --- a/include/gz/sim/components/Model.hh +++ b/include/gz/sim/components/Model.hh @@ -108,11 +108,8 @@ namespace serializers sdf::Errors errors = root.LoadSdfString(sdf); if (!root.Model()) { -<<<<<<< HEAD - ignwarn << "Unable to deserialize sdf::Model" << std::endl; -======= - gzwarn << "Unable to deserialize sdf::Model " << sdf<< std::endl; ->>>>>>> 1a881310c (Improve load times by skipping serialization of entities when unecessary. (#2596)) + ignwarn << "Unable to deserialize sdf::Model: " << sdf + << std::endl; return _in; }