XR Latency Optimization

Master-Client network architecture achieving <50ms synchronization accuracy across standalone VR headsets.

Role

VR Software Engineer

Tech Stack
Node.jsSocket.ioUnityC#Docker

The Challenge

In a shared VR concert experience with 5+ Meta Quest 3 devices, standard network replication caused Frame Desynchronization (Drift) of >100ms due to variable packet arrival times. This latency variance caused severe motion sickness and broke immersion. The challenge was to ensure that `VideoPlayer.Play()` triggers at the exact same physical moment on all devices, regardless of individual network jitter.

Architecture & Deep Dive

System Architecture

NTP-like Time Synchronization Protocol

MasterServerRTTCalculatorClientA(Quest3)ClientB(Quest3)LocalScheduler

Key Implementation

csharp
// Future Timestamp Execution Strategy
public void SchedulePlayback(long targetServerTime) {
    // 1. Calculate precise local offset using RTT
    // timeOffset = ServerTime - LocalTime - (RTT / 2)
    long localTargetTime = targetServerTime - this.timeOffset;
    
    // 2. Calculate exact wait duration
    // WaitTime = TargetTime - CurrentLocalTime
    double waitSeconds = (localTargetTime - DateTime.UtcNow.Ticks) / 10000000.0;
    
    if (waitSeconds > 0) {
        // 3. Schedule execution
        StartCoroutine(ExecuteAtTime(waitSeconds, () => {
            videoPlayer.Play(); // Triggers at the exact same physical moment
        }));
    } else {
        // Fallback: Seek to correct position if packet arrived late
        videoPlayer.time += Math.Abs(waitSeconds);
        videoPlayer.Play();
    }
}

Technical Trade-offs

Initially, I used `socket.broadcast.emit` to sync time, but this flooded the main thread of client devices (O(n^2) message complexity), causing stuttering. I refactored the architecture to use Targeted Emits (`io.to(guestId).emit`). This reduced CPU overhead by selectively sending correction data only to clients that drifted beyond the ±3 frame threshold, prioritizing network stability over constant updates.

Reliability & Validation

Error Handling Strategy

Developed a real-time CSV logging system to record `CurrentFrame` from all clients during stress tests. Implemented a Fail-Safe LOD (Level of Detail) system where devices exceeding 150ms RTT automatically downgrade video resolution to maintain synchronization priority. Disconnected clients can hot-swap back into the session using the calculated global time offset without restarting the experience.

Impact & Collaboration

Achieved ±1~2 Frame Synchronization (approx. 33ms) accuracy across 5 concurrent devices, validated through frame-logging metrics. This architecture was deployed commercially for the "SM REALIVE" K-Pop VR Theater, where the automated Docker/Kiosk Mode deployment pipeline reduced on-site setup time by 50%.

Frame Index Comparison

Frame Index Comparison

Frame Index Comparison

Frame Index Comparison

Frame Index Comparison