RUST · MULTIPLAYER NETCODE

gambetta-netcode-rs — Multiplayer Client-Side Prediction & Lag Compensation in Rust

gambetta-netcode-rs implements Gabriel Gambetta's fast-paced multiplayer netcode architecture in deterministic, zero-allocation Rust. It provides client-side input prediction, server state reconciliation, entity snapshot interpolation, and historical hitbox rewind for lag-compensated hitscan weapons.

$ cargo add gambetta-netcode-rs
GitHub ↗
One-Way Latency 100 ms
Simulates round-trip time: 200 ms
Packet Drop Rate 0%
Drop rate on upstream & downstream
Client 1 (You)
Seq: #0

WASD or Arrow Keys to move. Shoots with Space / button.

● Local ◌ Server Ghost ■ Remote Target
Authoritative Server
Tick: #0 (60Hz)

Validates inputs, simulates world, rewinds history on raycast.

🎯 Lag Comp Hit: Target Rewound 200ms
● C1 Server ■ C2 Server ◬ Rewound Hitbox
Client 2 (Remote Bot)
Autonomous Patrol

Moves autonomously back and forth across the arena.

■ Local C2 ● Interpolated C1
Unacknowledged Inputs
0
Awaiting server ACK
Reconciliations
0
Rollbacks & replays
Rewind Hit Delta
0.0 ms
History lookback
Hits Registered
0
Lag compensated
Performance Benchmarks

⚡ Nanosecond Netcode vs. JavaScript Reference (V8)

Comparing pure Rust zero-allocation ring buffers against Gabriel Gambetta's original JavaScript implementation. Read Full BENCHMARKS.md →

● 1,300× Faster than JS
Prediction Reconciliation
49.5 ns / rec
1,312× faster vs JS (65 µs)
100-Entity Interpolation
743.0 ns / frame
134.5 Million entities/sec
1,000-Entity MMO Scale
7.32 µs / frame
JS drops below 30 FPS (>18ms)
Server Lag Rewind Raycast
184.0 ns / ray
5.43 Million raycasts/sec
📐 Deterministic Verification & Parity Suite 10 / 10 Tests Passing
Subsystem Verification Target Tolerance Measured Performance Status
Reconciliation Convergence Δp < 10−4 m Δp = 0.00 × 10−4 m (Bit-Exact) PASS
Hermite Spline C¹ Continuity Δv < 0.001 m/s Δv < 10−3 m/s PASS
Lag Compensation Rewind Raycast Δd < 0.1 m Δd < 0.001 m PASS

📖 Gabriel Gambetta's Netcode Architecture in Pure Rust

1. Client-Side Prediction

Local player inputs are applied immediately to the local predicted state without waiting for the server round-trip. Every input is recorded in a circular buffer with a sequence number.

2. Server Reconciliation

The authoritative server simulates inputs in order and sends snapshots with the last processed sequence $S_{srv}$. The client discards inputs $\le S_{srv}$, snaps to server state, and reapplies all inputs $> S_{srv}$.

3. Remote Entity Interpolation

Remote entities cannot be predicted. Instead, snapshots are buffered and rendered 100ms in the past with linear or Hermite cubic spline interpolation, guaranteeing buttery smooth motion even over packet jitter.

4. Lag Compensation / Hitbox Rewind

When a client fires at $T_{shot} = T_{now} - \text{RTT}/2 - \text{render\_delay}$, the server temporarily rewinds all remote player colliders to that exact historical frame, runs raycasts, and restores current state.