[ROS2] Compile-time composing nodes vs Standalone nodes

asked 2022-03-16 08:36:29 -0500

parias gravatar image

Hi all,

What are the significant differences between compile-time composing nodes and standalone nodes? I'm asking it in terms of efficiency, and if changing my "rclcpp::Node" into a Component will decrease the performance.

Composable Node:

int main(int argc, char * argv[])
{
  rclcpp::init(argc, argv);
  rclcpp::executors::SingleThreadedExecutor exec;
  rclcpp::NodeOptions options;
  auto talker = std::make_shared<composition::Talker>(options);
  exec.add_node(talker);
  exec.spin();

  rclcpp::shutdown();    
  return 0;
}

Standalone Node:

int main(int argc, char * argv[])
{
  rclcpp::init(argc, argv);
  auto node = std::make_shared<rclcpp::Node>();
  rclcpp::spin(node);  

  rclcpp::shutdown();
  return 0;
}

Thanks in advance, Pedro

edit retag flag offensive close merge delete

Comments

I don't think there is much difference in terms of compile-time between composable nodes and stand-alone nodes. There could be some efficiency gains at runtime for a composable node. But this depends on what you are doing in terms of the type of data your node is going to handle.

pedro1713 gravatar image pedro1713  ( 2022-03-16 12:55:50 -0500 )edit

Ok, that's what I thought, thanks. Could you explain where the efficiency gains are at run-time? Thanks a lot.

parias gravatar image parias  ( 2022-03-17 04:07:30 -0500 )edit

Run time efficiency comes from the fact that all components are running as a single process. So, when you add more components to your node, these components can share process memory. Sharing process memory enables them to pass messages by just pointing to the process memory that stores the data, instead of serializing the data and sending it over the network. You can look here for an example of what I mean https://docs.ros.org/en/galactic/Tuto...

pedro1713 gravatar image pedro1713  ( 2022-03-17 07:15:28 -0500 )edit