From 3b1ca4881cd5a6eec25fb7509da33b4df93a5b3c Mon Sep 17 00:00:00 2001 From: Arjo Chakravarty Date: Thu, 5 Sep 2024 16:44:06 +0800 Subject: [PATCH 1/5] 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 --- include/gz/sim/components/Model.hh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/gz/sim/components/Model.hh b/include/gz/sim/components/Model.hh index decd6776ed..b4b9d2d9cc 100644 --- a/include/gz/sim/components/Model.hh +++ b/include/gz/sim/components/Model.hh @@ -75,6 +75,7 @@ namespace serializers } } + // Why bother even sending this. Wouldn't a blank string work? _out << "" << "" << (skip ? std::string() : modelElem->ToString("")) @@ -91,11 +92,17 @@ namespace serializers { sdf::Root root; std::string sdf(std::istreambuf_iterator(_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; } From da543ab3698840396f1f8209a7cbab9333e4a33e Mon Sep 17 00:00:00 2001 From: Arjo Chakravarty Date: Thu, 12 Sep 2024 13:34:10 -0700 Subject: [PATCH 2/5] Remove magic word Signed-off-by: Arjo Chakravarty --- include/gz/sim/components/Model.hh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/include/gz/sim/components/Model.hh b/include/gz/sim/components/Model.hh index b4b9d2d9cc..ed9967698a 100644 --- a/include/gz/sim/components/Model.hh +++ b/include/gz/sim/components/Model.hh @@ -76,10 +76,18 @@ namespace serializers } // Why bother even sending this. Wouldn't a blank string work? + if (skip) + { _out << "" << "" << (skip ? std::string() : modelElem->ToString("")) << ""; + + } + else + { + _out << ""; + } return _out; } @@ -90,15 +98,14 @@ 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.find("model") == std::string::npos) + if (sdf.empty()) { - gzwarn << "No model was sent\n"; return _in; } - // Its super expensive to create an SDFElement for some reason + // Its super expensive to create an SDFElement for some reason + sdf::Root root; sdf::Errors errors = root.LoadSdfString(sdf); if (!root.Model()) { From beadb783a16f73873e4c6129b091ad86c1f9a53e Mon Sep 17 00:00:00 2001 From: Arjo Chakravarty Date: Thu, 12 Sep 2024 16:19:04 -0700 Subject: [PATCH 3/5] Send empty string instead of using sentinel value. Signed-off-by: Arjo Chakravarty --- include/gz/sim/components/Model.hh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/gz/sim/components/Model.hh b/include/gz/sim/components/Model.hh index ed9967698a..f2f2ebfceb 100644 --- a/include/gz/sim/components/Model.hh +++ b/include/gz/sim/components/Model.hh @@ -75,8 +75,7 @@ namespace serializers } } - // Why bother even sending this. Wouldn't a blank string work? - if (skip) + if (!skip) { _out << "" << "" From b4865d554a78968b41b0b7ea85bfa19cca0e314d Mon Sep 17 00:00:00 2001 From: Arjo Chakravarty Date: Fri, 11 Oct 2024 08:33:17 +0800 Subject: [PATCH 4/5] Style Signed-off-by: Arjo Chakravarty --- include/gz/sim/components/Model.hh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/gz/sim/components/Model.hh b/include/gz/sim/components/Model.hh index f2f2ebfceb..524581f6c0 100644 --- a/include/gz/sim/components/Model.hh +++ b/include/gz/sim/components/Model.hh @@ -77,10 +77,10 @@ namespace serializers if (!skip) { - _out << "" - << "" - << (skip ? std::string() : modelElem->ToString("")) - << ""; + _out << "" + << "" + << modelElem->ToString("") + << ""; } else From a290bbfd370d30c12b65c07121f36571875bb94b Mon Sep 17 00:00:00 2001 From: Arjo Chakravarty Date: Tue, 29 Oct 2024 10:27:10 +0800 Subject: [PATCH 5/5] remove stray change Signed-off-by: Arjo Chakravarty --- examples/plugin/custom_sensor_system/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/plugin/custom_sensor_system/CMakeLists.txt b/examples/plugin/custom_sensor_system/CMakeLists.txt index 58fd5050ba..fee194db7b 100644 --- a/examples/plugin/custom_sensor_system/CMakeLists.txt +++ b/examples/plugin/custom_sensor_system/CMakeLists.txt @@ -20,7 +20,7 @@ include(FetchContent) FetchContent_Declare( sensors_clone GIT_REPOSITORY https://github.com/gazebosim/gz-sensors - GIT_TAG gz-sensors${GZ_SENSORS_VER} + GIT_TAG main ) FetchContent_Populate(sensors_clone) add_subdirectory(${sensors_clone_SOURCE_DIR}/examples/custom_sensor ${sensors_clone_BINARY_DIR})