-
Notifications
You must be signed in to change notification settings - Fork 310
Open
Description
[Feature] Zero-Copy JSON-RPC Processing for High-Performance MCP Servers
Problem Statement
Current JSON-RPC processing in the MCP Rust SDK:
- Creates unnecessary string allocations during parsing
- Uses standard
serde_json
which isn't optimized for high-throughput scenarios - Lacks optimization options for memory-constrained or high-concurrency environments
Proposal
Zero-copy JSON-RPC parser with:
- SIMD-optimized parsing using
simd-json
- Borrowed string references instead of owned strings where possible
- Hybrid architecture with automatic fallback for compatibility
- Feature-gated implementation (
zero-copy
feature) - no breaking changes
Proof of Concept
I've implemented a working POC to validate this approach:
- Branch:
feature/zero-copy-json-rpc
- Status: Functional implementation with comprehensive benchmarks
- Coverage: Core parsing, hybrid processing, performance measurement
What's Implemented
✅ Zero-copy parser with simd-json
✅ Hybrid processor with fallback logic
✅ Performance benchmarks showing +35% gains
✅ Feature-gated architecture
Benchmark Results
Significant Gains on Larger Payloads
Parsing + field extraction performance:
- Large JSON (1.5KB): 1,371ns vs 1,774ns → +23% faster
- XLarge JSON (3KB+): 2,145ns vs 3,284ns → +35% faster
Pure parsing performance:
- Large JSON: 1,285ns vs 1,802ns → +29% faster
- XLarge JSON: 2,220ns vs 3,236ns → +31% faster
Real-world MCP Scenarios
- Small payloads (~500B): Performance neutral (expected with SIMD libraries)
- Large tool responses: Significant improvements (23-35%)
- Batch processing: Major memory efficiency gains
What's Missing (pending discussion)
⏳ Comprehensive unit test suite
⏳ Edge case handling
⏳ Documentation
Code available here for review
❓ Questions for Discussion
Please, before investing in a complete implementation, I'd appreciate feedbacks
- Does this approach align with MCP's performance goals?
- Any concerns about the simd-json dependency, the architectural approach?
- Suggestions for the API design?
Thank you
Metadata
Metadata
Assignees
Labels
No labels