This document summarizes the investigation, benchmarks, and architectural evaluation of integrating SIMD-accelerated JSON parsers (such as simd-json) into OxyRoute (issue #163).
In high-throughput HTTP microservices, deserializing incoming JSON payloads into Python-accessible data structures can consume 30–50% of CPU time on compute-heavy routes.
Standard serde_json processes bytes sequentially using scalar CPU instructions. In contrast, SIMD (Single Instruction, Multiple Data) parsers leverage 128-bit (SSE4.2/NEON), 256-bit (AVX2), and 512-bit (AVX-512) vector registers to parse delimiters, string escapes, and numbers in parallel at rates up to 2.5–3.5 GB/s.
Testing parsing throughput across payload sizes:
| Payload Size | Typical Entity | serde_json + json_to_py |
SIMD Accelerated DOM | Relative Speedup |
|---|---|---|---|---|
| 1 KB | Single entity / CRUD item | ~1.2 µs | ~0.9 µs | 1.3x |
| 10 KB | Small list (50–100 items) | ~11.5 µs | ~6.1 µs | 1.9x |
| 100 KB | Bulk batch / export chunk | ~118 µs | ~42 µs | 2.8x |
| 1 MB | Large data ingest | ~1.24 ms | ~340 µs | 3.6x |
- For small payloads (< 2 KB), the dominant cost is CPython object allocation (
PyDict::new,PyList::new,PyString::newand GIL interaction). The raw parsing phase accounts for < 25% of the total time. - For large payloads (> 50 KB), the parsing phase dominates, making SIMD vectorization deliver 2.5x–3.6x throughput gains.
SIMD parsers modify the input slice in place to perform string unescaping and zero-copy slicing.
- OxyRoute Status: OxyRoute's request pipeline uses
PooledBuffer(Vec<u8>), which provides exclusive mutable ownership (&mut [u8]), satisfying the in-place parsing prerequisite.
- Hardcoding AVX-512 or AVX2 at compile time breaks execution on older x86_64 CPUs and ARM architectures (Apple Silicon, AWS Graviton).
- Runtime feature detection (
is_x86_feature_detected!("avx2")) with scalar fallback is required for standardmanylinuxbinary wheels.
Regardless of parser speed, converting JSON values into Python objects (PyObject) requires acquiring the GIL. For applications using Pydantic models with model_validate, bypassing intermediate Python dictionaries via direct Pydantic Core C-API bindings yields maximal speedups.
- Current Production Default: Retain
serde_json+ OxyRoute's zero-copyjson_to_pyfor universal portability and zero external C/assembly build dependencies. - High-Volume Endpoints: Offer an optional Cargo feature
simdfor environments with guaranteed AVX2/NEON support. - Pydantic DX Synergy: Pair SIMD parsing with direct Pydantic v2
CoreSchemavalidation to bypassPyDictallocation on large validated models.