Skip to content

[Feature] Zero-Copy JSON-RPC Processing for High-Performance MCP Servers #380

@bonpiedlaroute

Description

@bonpiedlaroute

[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

  1. Does this approach align with MCP's performance goals?
  2. Any concerns about the simd-json dependency, the architectural approach?
  3. Suggestions for the API design?

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions