Remove hook-path micro-optimizations

This commit is contained in:
Michael Mikovsky
2026-04-26 01:34:51 -06:00
parent 7a9e338d68
commit 01faebc44b
2 changed files with 21 additions and 49 deletions
+15 -23
View File
@@ -50,30 +50,22 @@ impl ProtocolEndpoint {
message: DataMessage, message: DataMessage,
) -> Result<EndpointOutcome, EndpointError> { ) -> Result<EndpointOutcome, EndpointError> {
let hook_id = header.hook_id.expect("validated"); let hook_id = header.hook_id.expect("validated");
let host_key = HookKey::new(self.path.clone(), hook_id); let key = if let Some(key) =
let key = if let Some(key) = self self.hooks
.hooks .resolve_active_key(&self.path, hook_id, &header.src_path)
.resolve_active_key_for_host(&host_key, &header.src_path)
{ {
key key
} else if self.hooks.pending(&host_key).is_some_and(|pending| {
pending.caller_src_path == header.src_path
&& pending.procedure_id == message.procedure_id
}) {
let local_ended = self
.hooks
.activate_pending_with_peer_end(&host_key, message.end_hook)
.expect("pending hook was checked above");
if message.end_hook && local_ended {
self.hooks.remove_active(&host_key);
}
return Ok(EndpointOutcome::Local(LocalEvent::Data {
header,
message,
hook_key: host_key,
}));
} else { } else {
return Ok(EndpointOutcome::Dropped); let pending_key = HookKey::new(self.path.clone(), hook_id);
if self.hooks.pending(&pending_key).is_some_and(|pending| {
pending.caller_src_path == header.src_path
&& pending.procedure_id == message.procedure_id
}) {
self.hooks.activate_pending(&pending_key);
pending_key
} else {
return Ok(EndpointOutcome::Dropped);
}
}; };
let Some(active) = self.hooks.active(&key) else { let Some(active) = self.hooks.active(&key) else {
@@ -109,10 +101,9 @@ impl ProtocolEndpoint {
message: FaultMessage, message: FaultMessage,
) -> Result<EndpointOutcome, EndpointError> { ) -> Result<EndpointOutcome, EndpointError> {
let hook_id = header.hook_id.expect("validated"); let hook_id = header.hook_id.expect("validated");
let pending_key = HookKey::new(self.path.clone(), hook_id);
if let Some(key) = self if let Some(key) = self
.hooks .hooks
.resolve_active_key_for_host(&pending_key, &header.src_path) .resolve_active_key(&self.path, hook_id, &header.src_path)
{ {
self.hooks.remove_active(&key); self.hooks.remove_active(&key);
return Ok(EndpointOutcome::Local(LocalEvent::Fault { return Ok(EndpointOutcome::Local(LocalEvent::Fault {
@@ -122,6 +113,7 @@ impl ProtocolEndpoint {
})); }));
} }
let pending_key = HookKey::new(self.path.clone(), hook_id);
if self if self
.hooks .hooks
.pending(&pending_key) .pending(&pending_key)
+6 -26
View File
@@ -98,29 +98,18 @@ impl HookTable {
/// Activation intentionally reuses the original hook id and host path, but swaps the /// Activation intentionally reuses the original hook id and host path, but swaps the
/// pending caller attribution into the active peer path used for data routing. /// pending caller attribution into the active peer path used for data routing.
pub fn activate_pending(&mut self, key: &HookKey) -> Option<()> { pub fn activate_pending(&mut self, key: &HookKey) -> Option<()> {
self.activate_pending_with_peer_end(key, false).map(|_| ())
}
/// Promotes a pending hook into the active table and returns whether the local side had
/// already ended before the peer accepted the hook.
pub fn activate_pending_with_peer_end(
&mut self,
key: &HookKey,
peer_ended: bool,
) -> Option<bool> {
let pending = self.pending.remove(key)?; let pending = self.pending.remove(key)?;
let local_ended = pending.local_ended;
self.insert_active( self.insert_active(
key.clone(), key.clone(),
ActiveHook { ActiveHook {
peer_path: pending.caller_src_path, peer_path: pending.caller_src_path,
procedure_id: pending.procedure_id, procedure_id: pending.procedure_id,
local_ended, local_ended: pending.local_ended,
peer_ended, peer_ended: false,
}, },
) )
.ok()?; .ok()?;
Some(local_ended) Some(())
} }
/// Inserts a live hook and its peer-path lookup entry. /// Inserts a live hook and its peer-path lookup entry.
@@ -194,26 +183,17 @@ impl HookTable {
return_path: &[String], return_path: &[String],
hook_id: u64, hook_id: u64,
peer_path: &[String], peer_path: &[String],
) -> Option<HookKey> {
let host_key = HookKey::new(return_path.to_vec(), hook_id);
self.resolve_active_key_for_host(&host_key, peer_path)
}
#[must_use]
pub fn resolve_active_key_for_host(
&self,
host_key: &HookKey,
peer_path: &[String],
) -> Option<HookKey> { ) -> Option<HookKey> {
if let Some(key) = self if let Some(key) = self
.active_by_peer .active_by_peer
.get(&host_key.hook_id) .get(&hook_id)
.and_then(|peer_paths| peer_paths.get(peer_path)) .and_then(|peer_paths| peer_paths.get(peer_path))
{ {
return Some(key.clone()); return Some(key.clone());
} }
self.active.contains_key(host_key).then(|| host_key.clone()) let host_key = HookKey::new(return_path.to_vec(), hook_id);
self.active.contains_key(&host_key).then_some(host_key)
} }
/// Marks the local side finished and returns `true` once both sides are finished. /// Marks the local side finished and returns `true` once both sides are finished.