topology: early-exit resolve_recipient before topology.json read (argus on #703)
This commit is contained in:
parent
7142e95c8f
commit
04f69c1fe1
1 changed files with 12 additions and 3 deletions
|
|
@ -76,11 +76,20 @@ pub fn parent_of(name: &str) -> Option<String> {
|
|||
///
|
||||
/// 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 `<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]
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue