Expand description
Zero-copy data handling utilities for performance-critical operations. Zero-copy message processing with minimal allocations
This module provides zero-allocation message handling using bytes::Bytes
for maximum throughput and minimal memory overhead.
§When to Use ZeroCopyMessage
Most users should use Message instead.
ZeroCopyMessage is designed for extreme performance scenarios where:
- You process millions of messages per second
- Every allocation matters for your performance profile
- You can defer deserialization until absolutely necessary
- You’re willing to trade ergonomics for performance
§Message vs ZeroCopyMessage
| Feature | Message | ZeroCopyMessage |
|---|---|---|
| Ergonomics | ✅ Excellent | ⚠️ Manual |
| Memory | ✅ Good | ✅ Optimal |
| Deserialization | Eager | Lazy |
| Multiple formats | ✅ JSON/CBOR/MessagePack | JSON only |
| ID storage | Stack/String | Arc (shared) |
| Use case | General purpose | Ultra-high throughput |
§Example Usage
use turbomcp_protocol::zero_copy::{ZeroCopyMessage, MessageId};
use bytes::Bytes;
// Create from raw bytes (no allocation)
let payload = Bytes::from(r#"{"method": "test", "id": 1}"#);
let mut msg = ZeroCopyMessage::from_bytes(MessageId::from("req-1"), payload);
// Lazy parsing - returns RawValue without full deserialization
let raw = msg.parse_json_lazy()?;
assert!(raw.get().contains("method"));
// Full deserialization when needed
let data: serde_json::Value = msg.deserialize()?;Performance Tip: Use ZeroCopyMessage in hot paths where you need to
route messages based on metadata but don’t need to parse the payload.
Modules§
- fast
- Fast utilities for message processing with SIMD acceleration
- mmap
Non- mmap - Memory-mapped file support (safe wrapper when feature is disabled)
Structs§
- Buffer
Pool - Buffer pool for reusing allocations
- Message
Batch - Zero-copy message batch for efficient bulk processing
- Message
Metadata - Lightweight message metadata
- Zero
Copy Message - Zero-copy message with lazy deserialization
Enums§
- Message
Id - Optimized message ID with Arc sharing