Skip to content

refactor(bridge): reduce standard bridge manager's memory usage#1276

Open
bdm-k wants to merge 3 commits intomainfrom
bdm-k/insane_snyder
Open

refactor(bridge): reduce standard bridge manager's memory usage#1276
bdm-k wants to merge 3 commits intomainfrom
bdm-k/insane_snyder

Conversation

@bdm-k
Copy link
Copy Markdown
Collaborator

@bdm-k bdm-k commented Apr 21, 2026

Closes #1209

Description

The previous BridgeInfo struct stored two full MqMsgBridge instances, holding many redundant fields that are identical for both directions.

This PR replaces BridgeInfo with a compact struct ManagedBridgeEntry:

struct ManagedBridgeEntry
{
  BridgeFactorySpec factory_spec;
  // Use -1 when not requested. Valid topic_local_id_t values are [0..MAX_TOPIC_LOCAL_ID).
  topic_local_id_t target_id_r2a;
  topic_local_id_t target_id_a2r;
  bool is_requested_r2a;
  bool is_requested_a2r;
};

struct BridgeFactorySpec
{
  // If set to std::nullopt, the factory functions reside in the main executable.
  std::optional<std::string> shared_lib_path;
  uintptr_t fn_offset_r2a;
  uintptr_t fn_offset_a2r;
};

BridgeFactorySpec takes advantage of the fact that the symbol_name field in BridgeFactoryInfo is only used to identify whether the factories are in the main executable. We set shared_lib_path to nullopt when the factories are in the main executable.

Received MqMsgBridge is now decomposed into ManagedBridgeEntry at reception time in register_request(), rather than being stored as is. The parameters of the related functions are updated accordingly.

This PR also adds handling of a previously ignored corner case (indeed, this can barely happen): a request is delegated to a bridge manager that has already removed the topic from its managed_bridges_. This is a timing issue.

Related links

How was this PR tested?

  • Autoware (required)
  • bash scripts/test/e2e_test_1to1.bash (required)
  • bash scripts/test/e2e_test_2to2.bash (required)
  • kunit tests (required when modifying the kernel module)
  • bash scripts/test/run_requires_kernel_module_tests.bash (required)
  • sample application

Notes for reviewers

Signed-off-by: bdm-k <kokusyunn@gmail.com>
@bdm-k bdm-k added the need-patch-update Bug fixes and other changes - requires PATCH version update label Apr 21, 2026
bdm-k added 2 commits April 22, 2026 17:37
…s into DirectedBridgeRef

Signed-off-by: bdm-k <kokusyunn@gmail.com>
Signed-off-by: bdm-k <kokusyunn@gmail.com>
@bdm-k bdm-k marked this pull request as ready for review April 22, 2026 10:00
@bdm-k bdm-k requested a review from kobayu858 as a code owner April 22, 2026 10:00
Copilot AI review requested due to automatic review settings April 22, 2026 10:00
@bdm-k bdm-k requested review from Koichi98 and sykwer as code owners April 22, 2026 10:00
Copy link
Copy Markdown
Contributor

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

Refactors the standard bridge manager to reduce memory usage by storing a compact per-topic entry instead of full MqMsgBridge requests for both directions, and updates the loader/factory plumbing accordingly (including a delegation corner-case guard).

Changes:

  • Replace stored per-topic BridgeInfo (two MqMsgBridges) with compact ManagedBridgeEntry + BridgeFactorySpec stored at request reception time.
  • Update StandardBridgeLoader API and caching to resolve factories from the compact spec and create bridges using (node, topic_name, qos) factories.
  • Add handling for delegation requests arriving after the owner manager has already dropped the topic from managed_bridges_.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/agnocastlib/src/bridge/standard/agnocast_standard_bridge_manager.cpp Decomposes incoming requests into compact entries, updates activation/delegation flow to use DirectedBridgeRef, and adds corner-case delegation handling.
src/agnocastlib/src/bridge/standard/agnocast_standard_bridge_loader.cpp Refactors factory resolution to use BridgeFactorySpec (optional lib path + two offsets) and instantiates bridges from topic name + direction.
src/agnocastlib/include/agnocast/bridge/standard/agnocast_standard_bridge_manager.hpp Introduces ManagedBridgeEntry/DirectedBridgeRef and switches loader storage to std::unique_ptr.
src/agnocastlib/include/agnocast/bridge/standard/agnocast_standard_bridge_loader.hpp Changes public loader/factory types (BridgeFn, BridgeFactorySpec) and loader constructor/create API.
src/agnocastlib/include/agnocast/bridge/agnocast_bridge_node.hpp Updates exported factory templates to match the new BridgeFn signature (topic name string instead of BridgeTargetInfo).

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

Comment on lines 17 to +26
using BridgeFn = std::shared_ptr<BridgeBase> (*)(
rclcpp::Node::SharedPtr, const BridgeTargetInfo &, const rclcpp::QoS &);
rclcpp::Node::SharedPtr, const std::string &, const rclcpp::QoS &);

struct BridgeFactorySpec
{
// If set to std::nullopt, the factory functions reside in the main executable.
std::optional<std::string> shared_lib_path;
uintptr_t fn_offset_r2a;
uintptr_t fn_offset_a2r;
};
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

Changing BridgeFn (and the corresponding factory functions) signature from (Node, BridgeTargetInfo, QoS) to (Node, std::string, QoS) is a public API/ABI break for any out-of-tree bridge factory libraries compiled against the old headers. If external factories/plugins are supported, consider providing a compatibility adapter (e.g., keep the old signature and forward to the new one) or explicitly documenting this as a breaking change and bumping the appropriate version.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

need-patch-update Bug fixes and other changes - requires PATCH version update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make BridgeInfo memory efficient

3 participants