From e1d694df365cb850e2953412d080960524fd1375 Mon Sep 17 00:00:00 2001 From: "chunmeng.gao" Date: Thu, 9 Apr 2026 18:46:18 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20Scope=20liveliness=20subscription=20by?= =?UTF-8?q?=20namespace=20to=20eliminate=20N=C2=B2=20broadcast?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When multiple bridges with different namespaces connect to the same router, each bridge was subscribing to all liveliness tokens (@/*/@ros2_lv/**), causing O(N²) control plane overhead as the router forwarded every token to every client. Now, bridges with a configured namespace subscribe only to tokens matching their namespace prefix (e.g., @/*/@ros2_lv/*/ns1§$*/**), leveraging the router's per-subscription interest matching to filter at the source. Bridges with default namespace "/" retain the original behavior for backward compatibility. Co-Authored-By: Claude Opus 4.6 (1M context) --- zenoh-plugin-ros2dds/src/lib.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/zenoh-plugin-ros2dds/src/lib.rs b/zenoh-plugin-ros2dds/src/lib.rs index 8dd30b0e..8bc8ccd6 100644 --- a/zenoh-plugin-ros2dds/src/lib.rs +++ b/zenoh-plugin-ros2dds/src/lib.rs @@ -414,13 +414,21 @@ enum AdminRef { impl ROS2PluginRuntime { async fn run(&mut self) { - // Subscribe to all liveliness info from other ROS2 plugins - let ke_liveliness_all = keformat!( - ke_liveliness_all::formatter(), - zenoh_id = "*", - remaining = "**" - ) - .unwrap(); + // Subscribe to liveliness info from other ROS2 plugins. + // If a namespace is configured, only subscribe to announcements matching this namespace + // to avoid receiving (and creating routes for) announcements from other namespaces. + let ke_liveliness_all = if self.config.namespace != "/" { + let ns_prefix = &self.config.namespace[1..]; // strip leading '/' + OwnedKeyExpr::try_from(format!("@/*/@ros2_lv/*/{}§$*/**", ns_prefix)) + .expect("Failed to build namespace-scoped liveliness key expression") + } else { + keformat!( + ke_liveliness_all::formatter(), + zenoh_id = "*", + remaining = "**" + ) + .unwrap() + }; let liveliness_subscriber = self .zsession .liveliness()