test: count deallocations in hot path guards

This commit is contained in:
floor-licker
2026-06-22 19:42:14 -04:00
parent c821262af5
commit 543329f4d6
4 changed files with 93 additions and 57 deletions
+16
View File
@@ -429,12 +429,28 @@ impl<'a> WebSocketBookApplier<'a> {
}
/// Apply a single WS text payload (useful for custom transports and for testing).
///
/// This convenience method consumes an owned `String`, so it may release that
/// buffer after processing. Use [`Self::apply_bytes_message`] for the
/// allocation-sensitive path when the caller owns a reusable mutable buffer.
pub fn apply_text_message(&mut self, text: String) -> Result<WsBookApplyStats> {
let stats = self.processor.process_text(text, self.books)?;
self.stream.stats.messages_received += 1;
self.stream.stats.last_message_time = Some(Utc::now());
Ok(stats)
}
/// Apply a single WS payload from a caller-owned mutable byte buffer.
///
/// The buffer is mutated by `simd-json`. After processor warmup, this is the
/// allocation-sensitive book-applier entry point because no owned message buffer
/// is created or dropped by this method.
pub fn apply_bytes_message(&mut self, bytes: &mut [u8]) -> Result<WsBookApplyStats> {
let stats = self.processor.process_bytes(bytes, self.books)?;
self.stream.stats.messages_received += 1;
self.stream.stats.last_message_time = Some(Utc::now());
Ok(stats)
}
}
impl<'a> Stream for WebSocketBookApplier<'a> {
+2 -1
View File
@@ -1,7 +1,8 @@
//! Zero-allocation-ish WebSocket hot-path processing.
//!
//! This module is focused on the "decode + apply" path for WS `book` events:
//! after warmup, processing a message should not perform heap allocations.
//! after warmup, existing-level happy-path processing should not perform heap
//! allocation, reallocation, or deallocation.
//!
//! Important: using the current tokio-tungstenite transport, the *network layer*
//! may still allocate when producing `Message::Text(String)`. This module aims to