PJS - Priority JSON Streaming Protocol
🚀 Priority-based streaming | 🎯 Progressive loading | 💾 Zero-copy operations | 🌐 WebAssembly ready
High-performance Rust library for priority-based JSON streaming with SIMD acceleration. Stream large JSON responses progressively, delivering critical data first while background data loads asynchronously.
v0.4.4: Enhanced WebAssembly with PriorityStream API, interactive browser demo, security limits, 519 tests passing, zero clippy warnings. Requires nightly Rust for zero-cost GAT abstractions.
Features
- ⚡ Blazing Fast - SIMD-accelerated parsing with optimized performance
- 🎯 Smart Streaming - Priority-based delivery sends critical data first, skeleton-first rendering
- 💾 Memory Efficient - Optimized progressive loading, bounded memory usage, zero-copy operations
- 🌐 WebAssembly - Browser and Node.js support with compact bundle (~70KB gzipped)
- 🔒 Secure - Input size limits, depth limits, DoS protection built-in
- 📊 Schema Aware - Automatic compression and semantic analysis
- 🔧 Production Ready - Clean Architecture, comprehensive tests, Prometheus metrics
Performance
| Benchmark | Performance Gain | Notes |
|---|---|---|
| Small JSON | Competitive | Comparable to industry standards |
| Medium JSON | ~3x faster | vs traditional parsers |
| Large JSON | ~6x faster | vs traditional parsers |
| Progressive Loading | ~5x faster | vs batch processing |
Installation
Or add to Cargo.toml:
[]
= "0.4"
Quick Start
Rust HTTP Server
use create_pjs_router;
async
Start server and test:
# Run example server
# Create session
# Stream data with priority
WebAssembly (Browser)
PriorityStream API (Recommended)
Simple Parser API
Interactive Demo
Try the Browser Demo with transport switching, performance benchmarks, and real-time metrics.
WebAssembly (Node.js)
import init from 'pjs-wasm';
import from 'fs/promises';
const wasmBuffer = await ;
await ;
const parser = ;
const frames = parser.;
frames.;
Build WASM from Source
# Install wasm-pack
|
# Build for different targets
Use Cases
- 📊 Real-time Dashboards - Show key metrics instantly, load details progressively
- 📱 Mobile Apps - Optimize for slow networks, critical data first
- 🛍️ E-commerce - Product essentials load immediately, reviews/images follow
- 📈 Financial Platforms - Trading data prioritized over historical charts
- 🎮 Gaming Leaderboards - Player rank appears instantly, full list streams in
Building
Prerequisites
# Requires nightly Rust for GAT features
Build Commands
# Standard build
# Run tests
# Run benchmarks
# Run demo servers
Feature Flags
# SIMD optimization
# Auto-detect (default)
# AVX2 support
# ARM NEON
# Memory allocators (optional)
# tikv-jemallocator
# mimalloc
# Features
# Schema validation (default)
# Schema-based compression
# Axum HTTP server
# WebSocket streaming
# Prometheus integration
Security
PJS includes built-in security features to prevent DoS attacks:
import from 'pjs-wasm';
const security =
. // 5 MB limit
.; // 32 levels max
const stream = ;
Default Limits:
- Max JSON size: 10 MB
- Max nesting depth: 64 levels
- Max array elements: 10,000
- Max object keys: 10,000
Architecture
PJS follows Clean Architecture with Domain-Driven Design:
- pjs-domain - Pure business logic, WASM-compatible
- pjs-wasm - WebAssembly bindings with PriorityStream API, security limits (44 tests)
- pjs-core - Rust implementation with HTTP/WebSocket integration (450+ tests)
- pjs-demo - Interactive demo servers with real-time streaming
- pjs-js-client - TypeScript/JavaScript client with WasmBackend transport
- pjs-bench - Comprehensive performance benchmarks
Implementation: ✅ Complete (519 tests, zero clippy warnings)
Contributing
Contributions welcome! Please ensure:
See CONTRIBUTING.md for guidelines.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.
Resources
PJS: Priority-based JSON streaming for instant user experiences.