Skip to content

improve lookup time for matches_any_publishers()#3084

Merged
fujitatomoya merged 3 commits intorollingfrom
issues/3067-2
Feb 26, 2026
Merged

improve lookup time for matches_any_publishers()#3084
fujitatomoya merged 3 commits intorollingfrom
issues/3067-2

Conversation

@fujitatomoya
Copy link
Copy Markdown
Collaborator

Description

Fixes #3067 (take 2 🎥 )

Is this user-facing behavior change?

Yes

Did you use Generative AI?

Partially with Claude Opus 4.6

Additional Information

see #3067 (comment)

…3077)

This reverts commit 1bf4e6a.

Signed-off-by: Tomoya Fujita <Tomoya.Fujita@sony.com>
Signed-off-by: Tomoya Fujita <Tomoya.Fujita@sony.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses performance overhead in rclcpp::experimental::IntraProcessManager::matches_any_publishers() (reported in #3067) by replacing the per-call scan over publishers with a constant-time lookup keyed by publisher GID.

Changes:

  • Add a rmw_gid_t-keyed unordered_map (gid_to_publisher_info_) to enable O(1) publisher-existence checks by GID.
  • Populate/maintain the GID map in add_publisher() / remove_publisher() and use it in matches_any_publishers().
  • Update intra-process manager unit test mocks to provide a stable mock GID and get_gid().

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
rclcpp/src/rclcpp/intra_process_manager.cpp Inserts/erases a GID→publisher mapping and switches matches_any_publishers() to a hash lookup.
rclcpp/include/rclcpp/experimental/intra_process_manager.hpp Adds rmw_gid_t hashing/equality helpers and a new gid_to_publisher_info_ member type.
rclcpp/test/rclcpp/test_intra_process_manager.cpp Extends mock PublisherBase with a mock GID and get_gid() to support the new lookup path in tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@mini-1235 mini-1235 left a comment

Choose a reason for hiding this comment

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

Thanks @fujitatomoya! I don't have time right now to run a full performance test again, but based on CPU usage observations, I can clearly see improved performance with this PR!

@mini-1235
Copy link
Copy Markdown
Contributor

FYI @SteveMacenski

Signed-off-by: Tomoya Fujita <Tomoya.Fujita@sony.com>
@fujitatomoya
Copy link
Copy Markdown
Collaborator Author

@mini-1235 do we have regression with this PR like #3068 (comment)? (that is what i am really interested in before merge... 😅 )

@fujitatomoya
Copy link
Copy Markdown
Collaborator Author

Pulls: #3084
Gist: https://gist.githubusercontent.com/fujitatomoya/09aa9a979dd9efb5af34bd1c66f2b50a/raw/e49ac34b8281de5782cb618dd2e87b3b118d2b49/ros2.repos
BUILD args: --packages-above-and-dependencies rclcpp
TEST args: --packages-above rclcpp
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/18311

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

@mini-1235
Copy link
Copy Markdown
Contributor

@mini-1235 do we have regression with this PR like #3068 (comment)? (that is what i am really interested in before merge... 😅 )

No, my comment above reflects the results from testing in Nav2, and I did not observe any regressions this time

@fujitatomoya
Copy link
Copy Markdown
Collaborator Author

  • Linux-rhel Build Status
  • Windows Build Status

@fujitatomoya fujitatomoya merged commit aea98d6 into rolling Feb 26, 2026
3 checks passed
jplapp added a commit to pixel-robotics/rclcpp that referenced this pull request Mar 5, 2026
Adds O(1) hash-map lookup for matches_any_publishers() instead of
linear scan over all publishers. Test changes excluded (jazzy mock
class differs from rolling).

Upstream: ros2#3084

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
jplapp added a commit to pixel-robotics/rclcpp that referenced this pull request Mar 5, 2026
Adds O(1) hash-map lookup for matches_any_publishers() instead of
linear scan over all publishers. Test changes excluded (jazzy mock
class differs from rolling).

Upstream: ros2#3084

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Investigate performance of matches_any_publishers() when enabling intraprocess

4 participants