topology: early-exit resolve_recipient before topology.json read (argus on #703)

This commit is contained in:
damocles 2026-05-31 11:38:31 +02:00 committed by Mara
commit 04f69c1fe1

View file

@ -76,11 +76,20 @@ pub fn parent_of(name: &str) -> Option<String> {
/// ///
/// Returns an owned `String` for the rewritten recipient so callers /// Returns an owned `String` for the rewritten recipient so callers
/// can plug it straight into [`crate::broker::Broker::send`] without /// can plug it straight into [`crate::broker::Broker::send`] without
/// borrow-juggling around the temporary lookup. Cheap — the resolved /// borrow-juggling around the temporary lookup.
/// path clones twice in the worst case (parent name + return), no-op ///
/// in the common case (recipient already a real label). /// Fast path: ordinary recipient names (the overwhelming majority of
/// sends) short-circuit before touching the disk — only `<parent>`
/// triggers the `read()` of `topology.json`. Sentinel-free traffic
/// pays a single string compare; the disk read is amortised across
/// every `<parent>` send (per argus on #703#issuecomment-8750).
#[must_use] #[must_use]
pub fn resolve_recipient(sender: &str, to: &str) -> String { 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) resolve_recipient_in(&read(), sender, to)
} }