mirror of
https://github.com/floor-licker/polyfill-rs.git
synced 2026-08-17 22:48:07 +00:00
test: count deallocations in hot path guards
This commit is contained in:
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user