Skip to content

deprecate rclcpp::spin_some and rclcpp::spin_all#2848

Merged
fujitatomoya merged 7 commits intorollingfrom
asoragna/deprecate-global-spin-some-all
Aug 26, 2025
Merged

deprecate rclcpp::spin_some and rclcpp::spin_all#2848
fujitatomoya merged 7 commits intorollingfrom
asoragna/deprecate-global-spin-some-all

Conversation

@alsora
Copy link
Collaborator

@alsora alsora commented May 17, 2025

Description

Deprecate rclcpp::spin_some and rclcpp::spin_all.
These functions can lead to very poor performance for developers who are not aware that calling them will:

  • create an executor
  • add the node to the executor
  • do the spin
  • destroy the executor

If called in a loop, you are wasting a lot of CPU cycles repeating those operations every time.
This instead is a lot more efficient because only the spin operation is repeated as expected.

SingleThreadedExecutor executor;
executor.add_node(node);
while (should_spin)
{
    executor.spin_some();
}

Adding and removing nodes from executors are expensive operations that shouldn't be done at "steady state" of the system.

IMPORTANT
In this PR I'm also re-ordering the events-executor constructor arguments so that this becomes possible:

MyExecutorType executor(options);

Now all executors take the executor options as first argument.

Is this user-facing behavior change?

Yes, deprecating some functions and modifying a constructor (although it's in the experimental namespace)

Did you use Generative AI?

No

closes #2675

@alsora alsora force-pushed the asoragna/deprecate-global-spin-some-all branch 2 times, most recently from e8e8faf to f1e7310 Compare May 17, 2025 08:21
@fujitatomoya
Copy link
Collaborator

@Mergifyio rebase

@mergify
Copy link
Contributor

mergify bot commented Jul 24, 2025

rebase

✅ Branch has been successfully rebased

@fujitatomoya fujitatomoya force-pushed the asoragna/deprecate-global-spin-some-all branch from f9d55bd to 5cbdae6 Compare July 24, 2025 11:53
@fujitatomoya
Copy link
Collaborator

Pulls: #2848
Gist: https://gist.githubusercontent.com/fujitatomoya/fa4647ec68c1811cf6576850ed1d022a/raw/3ac4860bbd88f8c2ba1df0e0962127021685089d/ros2.repos
BUILD args: --packages-above-and-dependencies rclcpp rclcpp_action rclcpp_lifecycle
TEST args: --packages-above rclcpp rclcpp_action rclcpp_lifecycle
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/16595

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

alsora added 3 commits August 20, 2025 15:38
…match the other executors

Signed-off-by: Alberto Soragna <alberto.soragna@gmail.com>
Signed-off-by: Alberto Soragna <alberto.soragna@gmail.com>
…omments

Signed-off-by: Alberto Soragna <alberto.soragna@gmail.com>
@fujitatomoya fujitatomoya force-pushed the asoragna/deprecate-global-spin-some-all branch from 5cbdae6 to c35493d Compare August 20, 2025 06:39
Signed-off-by: Tomoya Fujita <Tomoya.Fujita@sony.com>
@fujitatomoya
Copy link
Collaborator

Pulls: #2848, ros2/message_filters#201, ros2/system_tests#574, ros2/demos#734, ros2/examples#422, ros2/geometry2#821
Gist: https://gist.githubusercontent.com/fujitatomoya/729c2c9e3f31efc10217a07d09b682c5/raw/80936104a2cae37018c8996fb8071ceffb79df0c/ros2.repos
BUILD args: --packages-above-and-dependencies rclcpp rclcpp_action rclcpp_lifecycle message_filters test_communication test_rclcpp pendulum_control dummy_map_server dummy_sensors examples_rclcpp_minimal_publisher examples_rclcpp_minimal_action_client tf2_ros
TEST args: --packages-above rclcpp rclcpp_action rclcpp_lifecycle message_filters test_communication test_rclcpp pendulum_control dummy_map_server dummy_sensors examples_rclcpp_minimal_publisher examples_rclcpp_minimal_action_client tf2_ros
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/16754

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

Signed-off-by: Alejandro Hernandez Cordero <ahcorde@gmail.com>
@ahcorde
Copy link
Contributor

ahcorde commented Aug 21, 2025

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

@fujitatomoya
Copy link
Collaborator

after ros/ros_tutorials#183 is merged, we can start the CI only with this PR. (there should not be any deprecated warning.)

alsora added 2 commits August 23, 2025 11:33
Signed-off-by: Alberto Soragna <alberto.soragna@gmail.com>
Signed-off-by: Alberto Soragna <alberto.soragna@gmail.com>
@alsora alsora force-pushed the asoragna/deprecate-global-spin-some-all branch from a866ac9 to c8c7b06 Compare August 23, 2025 09:33
@ahcorde
Copy link
Contributor

ahcorde commented Aug 25, 2025

Pulls: #2848
Gist: https://gist.githubusercontent.com/ahcorde/64c57c2436820e000fc06a5510aafcac/raw/3ac4860bbd88f8c2ba1df0e0962127021685089d/ros2.repos
BUILD args: --packages-above-and-dependencies rclcpp rclcpp_action rclcpp_lifecycle
TEST args: --packages-above rclcpp rclcpp_action rclcpp_lifecycle
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/16789

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

@fujitatomoya fujitatomoya merged commit bdab46d into rolling Aug 26, 2025
2 of 3 checks passed
@alsora alsora deleted the asoragna/deprecate-global-spin-some-all branch August 26, 2025 12:35
nbbrooks added a commit to moveit/moveit2 that referenced this pull request Oct 12, 2025
* Fix image_common NodeT deprecation warnings from ros-perception/image_common#352 - migrate to NodeInterfaces

* Fix image_common rmw_qos_profile_t deprecation warnings from ros-perception/image_common#364 - migrate to rclcpp::QoS

* Fix rviz update float deprecation warnings from ros2/rviz#1533 - migrate to std::chrono::duration

* Fix geometry2 tf2_ros .h deprecation warnings from ros2/geometry2#805 - migrate Kilted and Rolling to .hpp

* Fix geometry2 tf2_ros NodeT deprecation warnings from ros2/geometry2#714 - migrate to NodeInterfaces

* Fix rclcpp spin_some deprecation warnings from ros2/rclcpp#2848 - migrate to SingleThreadedExecutor

---------

Co-authored-by: Andrea <realeandrea@yahoo.it>
helen9975 pushed a commit to personalrobotics/moveit2 that referenced this pull request Feb 17, 2026
* Fix image_common NodeT deprecation warnings from ros-perception/image_common#352 - migrate to NodeInterfaces

* Fix image_common rmw_qos_profile_t deprecation warnings from ros-perception/image_common#364 - migrate to rclcpp::QoS

* Fix rviz update float deprecation warnings from ros2/rviz#1533 - migrate to std::chrono::duration

* Fix geometry2 tf2_ros .h deprecation warnings from ros2/geometry2#805 - migrate Kilted and Rolling to .hpp

* Fix geometry2 tf2_ros NodeT deprecation warnings from ros2/geometry2#714 - migrate to NodeInterfaces

* Fix rclcpp spin_some deprecation warnings from ros2/rclcpp#2848 - migrate to SingleThreadedExecutor

---------

Co-authored-by: Andrea <realeandrea@yahoo.it>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deprecate all spin_xxx functions in rclcpp namespace instead of spin.

5 participants