Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimize header includes by moving impl to .cpp files #331

Merged
merged 2 commits into from
Mar 21, 2024

Conversation

Rayman
Copy link
Contributor

@Rayman Rayman commented Feb 20, 2024

I'm trying to improve compilation times. One obvious candidate was this package. I've tried to remove includes of rclcpp (which is huge) and move all implementations to a cpp file. I did not modify any code, only move it.

@Rayman Rayman force-pushed the refactor/minimize-header-includes branch from 7357420 to 2eada65 Compare February 20, 2024 16:20
@Rayman
Copy link
Contributor Author

Rayman commented Mar 1, 2024

Hello, can I get some feedback on my PR?

@ct2034
Copy link
Collaborator

ct2034 commented Mar 1, 2024

Hi @Rayman. To be honest, I prefer the header-based approach right now for simplicity. Do you know that this has a noticeable speed improvement?

@Rayman
Copy link
Contributor Author

Rayman commented Mar 1, 2024

The templates from rclcpp are relatively heavy, especially create_subscriber. So by moving them to the implementation files we can avoid recompiling them. diagnostics only uses create_publisher, which is less heavy but still the same argument applies.

Also the include rclcpp/rclcpp.hpp includes everything, and is pretty huge. Most of the time in the frontend is spent parsing these headers.

With this PR our software still compiles perfectly fine, so no change needed in dependent software

If you want I can show you some measurements, the results are not big but multiplied by every node in our system (100s) it becomes noticeable.

Comment on lines +39 to +40
#include "rclcpp/rclcpp.hpp"

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see that it was probably wrong that this was missing before. But now it is technically a breaking change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it is a breaking change. So this should not be merged into iron, but in rolling. I'll then get released for jazzy

@ct2034 ct2034 added the ros2 PR tackling a ROS2 branch label Mar 1, 2024
@Rayman
Copy link
Contributor Author

Rayman commented Mar 21, 2024

I did some quick tests with a simple node that has a diagnostic_updater. The compilation time went from 5 to 2.5 seconds. I only measured this once so there could be some variability.

compile-master
compile-branch

@ct2034 ct2034 changed the base branch from ros2 to ros2-jazzy March 21, 2024 22:17
Copy link
Collaborator

@ct2034 ct2034 left a comment

Choose a reason for hiding this comment

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

Thanks for you contribution

@ct2034 ct2034 merged commit 1af8c80 into ros:ros2-jazzy Mar 21, 2024
22 of 23 checks passed
@Rayman Rayman deleted the refactor/minimize-header-includes branch March 22, 2024 08:31
@ct2034
Copy link
Collaborator

ct2034 commented Jul 22, 2024

💚 All backports created successfully

Status Branch Result
ros2

Questions ?

Please refer to the Backport tool documentation

ct2034 pushed a commit to ct2034/diagnostics that referenced this pull request Jul 22, 2024
* Minimize header includes by moving impl to .cpp files
* Make sure to build a shared library

(cherry picked from commit 1af8c80)

# Conflicts:
#	diagnostic_updater/include/diagnostic_updater/diagnostic_updater.hpp
ct2034 pushed a commit that referenced this pull request Jul 22, 2024
* Minimize header includes by moving impl to .cpp files
* Make sure to build a shared library

Signed-off-by: Christian Henkel <[email protected]>
ct2034 added a commit that referenced this pull request Jul 22, 2024
…usage of rclcpp::ok with a non-default context (#352)  (#390)

* Minimize header includes by moving impl to .cpp files (#331)

* Minimize header includes by moving impl to .cpp files
* Make sure to build a shared library

Signed-off-by: Christian Henkel <[email protected]>

* Fix usage of rclcpp::ok with a non-default context (#352)

* Fix usage of rclcpp::ok with a non-default context

The current implementation calls `rclcpp::ok` without any arguments,
which amounts to verifying that the global default context is valid. In
the case where a node is added to a custom context, and the global
context is not used, `rclcpp::ok` without any arguments will always
return `false` since the global context has never been initialized. To
fix it, pass to rclcpp the context that's available via the node's base
interface.

* Add a test for custom context

Signed-off-by: Christian Henkel <[email protected]>

---------

Signed-off-by: Christian Henkel <[email protected]>
Co-authored-by: Ramon Wijnands <[email protected]>
Co-authored-by: Hervé Audren <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ros2 PR tackling a ROS2 branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants