DocumentationCore Protocol

Benchmarks & Performance

PaindaProtocol is designed specifically for React-based multiplayer games and heavily relies on Operational Transformations and Myers Diff to drastically reduce network load.

1. The Payload Problem

In a typical Socket.io game, sending 60 frames per second over WebSockets means blasting a massive GameState object to every client on every tick. This wastes CPU, hogs network bandwidth, and results in lag spikes for players on weak connections.

Socket.io Timeline (100ms)

[T+0ms]: emit("state", { players: [ ...100 items ] }) // 32 KB [T+16ms]: emit("state", { players: [ ...100 items ] }) // 32 KB [T+32ms]: emit("state", { players: [ ...100 items ] }) // 32 KB

Total Bandwidth: ~2 MB/s per client.

2. The Delta Engine Solution

PaindaProtocol features a highly optimized Delta Engine inside @painda/gaming. Using server.emitDelta automatically calculates deep object diffs before pushing to the network.

PaindaProtocol Timeline (100ms)

[T+0ms]: emitDelta("state", { players: [ ...100 items ] }) // 32 KB (baseline) [T+16ms]: emitDelta("state", { players: [ { x: 10, y: 15 } ] }) // 40 bytes! [T+32ms]: emitDelta("state", undefined) // 0 bytes (no changes!)

Total Bandwidth: ~0.08 MB/s per client (96% reduction!)

3. React Integration: O(ND) Myers Diff

Sending raw diffs works well for objects, but Array splicing usually breaks React states if not handled immutably. We ported the Myers O(ND) Diffing Algorithm to efficiently detect Array inserts and deletes.

When you use patchImmutable(), it reads these Array splice operations and generates a pristine, deep-cloned React state that perfectly matches the server, causing zero unnecessary re-renders.

const [gameState, setGameState] = useState<State>();

useEffect(() => {
    client.on("game:delta", (delta) => {
        // Automatically applies Myers array splices to React State
        setGameState(prev => patchImmutable(prev, delta)); 
    });
}, []);