Skip to content

Conversation

ntfshard
Copy link
Contributor

🦟 Bug fix

Fixes #

Summary

  • Using exception for a flow control is not a very good approach in a different points of view, like from a code structure or performance perspective (https://godbolt.org/z/s883vGr9f). I'd propose to use std::holds_alternative as a more simple way to improve this part of code
  • Found some place with seems redundant usage of exception handling, I'll put discussion comment in review to discuss.
  • Removed some extra vectors/string copying in VisualizationCapabilities.cc and SystemLoader.cc; For a VisualizationCapabilities, code a little bit convoluted, but seems it's legit change
  • Made some expressions more Cpp-like (added const around my changes, .empty() instead of == "" or use .front() instead of iterator to *begin(). Yes, compiler can optimize it in release mode, but in debug it will be exactly)
  • Fixed typos

Sorry for combining it in a one PR, splitting it apart will be too tedious I suppose (and for me, and fore maintainers)

Checklist

  • Signed all commits for DCO
  • Added tests
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

Signed-off-by: Maksim Derbasov <ntfs.hard@gmail.com>
@ntfshard ntfshard requested a review from mjcarroll as a code owner January 12, 2025 04:06
@github-actions github-actions bot added 🏛️ ionic Gazebo Ionic 🪵 jetty Gazebo Jetty labels Jan 12, 2025

<link name='front_right_wheel'>
<pose>0.554282 -0.625029 -0.025 -1.5707 0 0</pose>
<pose>0.554283 -0.625029 -0.025 -1.5707 0 0</pose>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in other 3 places in file it's 0.554283, but here it's 0.554282, aligned to simplify find-replace for users

Comment on lines 715 to 716
} catch (std::bad_variant_access &)
}
catch (std::bad_variant_access &)
Copy link
Contributor Author

@ntfshard ntfshard Jan 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed codestyle and conveniently it's one of the cases where I suppose try-catch block is redundant

Whole list:
TransformControl.cc:479
TransformControl.cc:558
TransformControl.cc:592
TransformControl.cc:681
TransformControl.cc:694
TransformControl.cc:716

AFAIU, SetUserData is belong to gz-rendering/base/BaseNode.hh, which just assigning to std::variant, which is inside of std::map; and operator= can throw only if type which assigning throwing something
I can be wrong

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it may not be necessary as well. There are other places in the code base that don't wrap SetUserData with try/catch

Copy link
Contributor Author

@ntfshard ntfshard Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll clean-up it

Quite funny, compiler can optimize a try-catch block if it can see all side effects https://godbolt.org/z/7co957W1h

@codecov
Copy link

codecov bot commented Jan 12, 2025

Codecov Report

Attention: Patch coverage is 39.28571% with 17 lines in your changes missing coverage. Please review.

Please upload report for BASE (gz-sim9@d83d135). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/gui/plugins/select_entities/SelectEntities.cc 0.00% 9 Missing ⚠️
...lization_capabilities/VisualizationCapabilities.cc 0.00% 3 Missing ⚠️
.../gui/plugins/transform_control/TransformControl.cc 0.00% 2 Missing ⚠️
.../plugins/component_inspector/ComponentInspector.cc 0.00% 1 Missing ⚠️
...int_position_controller/JointPositionController.cc 0.00% 1 Missing ⚠️
src/gui/plugins/plot_3d/Plot3D.cc 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             gz-sim9    #2714   +/-   ##
==========================================
  Coverage           ?   68.80%           
==========================================
  Files              ?      341           
  Lines              ?    33076           
  Branches           ?        0           
==========================================
  Hits               ?    22759           
  Misses             ?    10317           
  Partials           ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

using namespace gz::sim;

/// Sensor prefix to be used. All envionment_sensors are to be prefixed by
/// Sensor prefix to be used. All enviornment_sensors are to be prefixed by
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Sensor prefix to be used. All enviornment_sensors are to be prefixed by
/// Sensor prefix to be used. All environment_sensors are to be prefixed by

Comment on lines 715 to 716
} catch (std::bad_variant_access &)
}
catch (std::bad_variant_access &)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it may not be necessary as well. There are other places in the code base that don't wrap SetUserData with try/catch

Signed-off-by: Maksim Derbasov <ntfs.hard@gmail.com>
Copy link
Contributor

@azeey azeey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love these cleanup PRs. Thank you!!

@ntfshard
Copy link
Contributor Author

ntfshard commented Jan 18, 2025

Maybe we can wrap-up it? I have a fix for a flakiness in test/integration/battery_plugin.cc and fix for lost threading sync for src/systems/battery_plugin/LinearBatteryPlugin.cc
But this PR is touching battery_plugin.cc and it will be conflict if one of them will be merged

(yes, I touched this file before due to I spotted instability there but it took time to figure out what's the problem)

@iche033 iche033 merged commit c72be04 into gazebosim:gz-sim9 Jan 21, 2025
10 checks passed
@ntfshard ntfshard deleted the better_variant_usage branch January 22, 2025 02:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🏛️ ionic Gazebo Ionic 🪵 jetty Gazebo Jetty

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants