diff --git a/hive-c0re/src/topology.rs b/hive-c0re/src/topology.rs index a63855f4..128332cb 100644 --- a/hive-c0re/src/topology.rs +++ b/hive-c0re/src/topology.rs @@ -76,11 +76,20 @@ pub fn parent_of(name: &str) -> Option { /// /// Returns an owned `String` for the rewritten recipient so callers /// can plug it straight into [`crate::broker::Broker::send`] without -/// borrow-juggling around the temporary lookup. Cheap — the resolved -/// path clones twice in the worst case (parent name + return), no-op -/// in the common case (recipient already a real label). +/// borrow-juggling around the temporary lookup. +/// +/// Fast path: ordinary recipient names (the overwhelming majority of +/// sends) short-circuit before touching the disk — only `` +/// triggers the `read()` of `topology.json`. Sentinel-free traffic +/// pays a single string compare; the disk read is amortised across +/// every `` send (per argus on #703#issuecomment-8750). #[must_use] pub fn resolve_recipient(sender: &str, to: &str) -> String { + // Early exit: only sentinel recipients need topology lookup. This + // keeps the cost of a normal `send` at one string comparison. + if to != hive_sh4re::PARENT_RECIPIENT { + return to.to_owned(); + } resolve_recipient_in(&read(), sender, to) }