ros2 / ros2/rclcpp

Compilation performance is rather slow

Open
#1,949 11 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted
Dominant language
C++
Stars
805
Forks
564
Avg merge
1d 17h
Merged PRs (30d)
27

Description

Bug report

I find the compile times for simple ROS logic to be quite high. We have a system with around 100 topics set up with a CI toolchain etc. As build times increased I did some digging around and one of the issue is the compilation performance of ros function calls (eg create_subscription)

Required Info:

  • Operating System:
    • Ubuntu 20.04
  • Installation type:
    • apt install ros-galactic-dekstop
  • Version or commit hash:
    • ros-galactic-desktop/focal,now 0.9.3-2focal.20220430.204723 amd64
  • DDS implementation:
    • default
  • Client library (if applicable):
    • rclcpp
Steps to reproduce issue

Minimal example that creates some subscriptions:

#include <geometry_msgs/msg/pose_array.hpp>
#include <geometry_msgs/msg/quaternion_stamped.hpp>
#include <geometry_msgs/msg/twist.hpp>
#include <rclcpp/node.hpp>

void test() {
  rclcpp::Node node("test");
  node.create_subscription<geometry_msgs::msg::Twist>("test1", rclcpp::QoS(1), [](geometry_msgs::msg::Twist::ConstSharedPtr) {});
  node.create_subscription<geometry_msgs::msg::PoseArray>("test2", rclcpp::QoS(1), [](geometry_msgs::msg::PoseArray::ConstSharedPtr) {});
  node.create_subscription<geometry_msgs::msg::QuaternionStamped>("test3", rclcpp::QoS(1), [](geometry_msgs::msg::QuaternionStamped::ConstSharedPtr) {});
}

compile:
time /usr/bin/c++ -isystem /opt/ros/galactic/include -Wall -Wextra -std=gnu++17 -c test.cc

Expected behavior

I don't now? Up to 2s max?

Actual behavior

On my system (intel i7@1.9Ghz x8, 16G, SSD, gcc 9.4.0):

  • gcc takes about 8 seconds.
  • (clang about 4.5 seconds, significantly faster but I can not make the switch at this moment...)

The above example results in an object file that's 11M and contains about 17.000 symbols, so I think all the in-header and template definitions are exploding a bit.

Is there a work around that someone knows of, or is it possible to make a leaner header file?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported case in test.cc with the provided g++ command and compare its timing with clang. Read the rclcpp client-library path exercised by Node::create_subscription and inspect the generated object size and symbols. Done means identifying a supported cause or workaround and measuring a concrete compilation improvement.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.