Skip to content

Performance Tips

Our Engine and Client SDK are designed to emit messages only when triggered by the app's logic.

WARNING

If the server and client are not exchanging messages, the client will be disconnected due to a timeout specified in the project settings.

Update Frequency and Network Traffic

Higher update rates create smoother gameplay and more current game states, but substantially increase network traffic.

Since network issues like lag and packet loss are unavoidable, clients should implement interpolation techniques for key values to maintain smooth gameplay between updates.

Examples:

Character Position Updates: In a fast multiplayer game.

  • Low frequency (10 updates/second): Character movement may appear choppy.
  • High frequency (60 updates/second): Smooth movement, but 6x more network traffic.
  • With interpolation: Even at 20 updates/second, client-side prediction can create smooth movement between updates.

Player Inventory: In an MMO.

  • Low frequency (1 update/second): Sufficient for non-critical data like inventory changes.
  • High frequency (10 updates/second): Unnecessary for slow-changing data, wastes bandwidth.
  • No interpolation needed: Discrete data that doesn't benefit from prediction.

Optimizing Network Traffic

Efficient network usage is crucial for smooth multiplayer experiences. Here are strategies to minimize data transmission while maintaining game quality.

Principles

  • Minimize Data Transmission: Send only essential information to reduce bandwidth usage.
  • Batch Operations: Combine multiple commands into a single message to avoid network overhead. Learn more
  • Hard-code Room Settings: Store room settings on the client side to reduce traffic. Learn more
  • Client-Side Computation: Calculate non-critical data on the client side instead of synchronizing it.
  • Smart Update Strategies: Use techniques like delta compression and event-based updates.

Optimization Techniques and Examples

By implementing techniques mentioned below, you can significantly reduce network traffic while maintaining responsive and synchronized gameplay experiences.

Event-Based Updates

Send significant changes or events rather than continuous state updates.

Example: MOBA Ability Usage

  • Instead of constantly updating ability cooldowns, send an event when an ability is used.
  • Client calculates remaining cooldown based on timestamp and known ability details.

Predictive Movement

Allow clients to predict movement and reconcile with server updates.

Example: Racing Game

  • Send car position and velocity updates at lower frequency (e.g., every 200ms).
  • Client predicts car positions between updates using physics simulation.
  • Reconcile with server data to correct any drift.

State-Based Animations

Derive animations from game state rather than synchronizing animation data.

Example: Fighting Game

  • Send only player actions (e.g., "punch initiated").
  • Client determines appropriate animation based on character state and action.

Relevance Filtering

Only send data relevant to each client.

Example: Open World MMO

  • Divide the world into sectors.
  • Only send detailed updates for entities in the player's current and adjacent sectors.
  • Use lower update frequencies for distant objects.

Delta Compression

Transmit only changes in state since the last update.

Example: Strategy Game Unit Movement

  • Instead of sending full position coordinates, send movement deltas.
  • Client applies these deltas to the last known position.
  • Periodically send full state updates to prevent error accumulation.

Optimize Data Types

Use the appropriate data types in Models, Server, and Client Commands: Models

Reduce Send Frequency

  • Lower the sending rate, ideally below 10 if possible, depending on gameplay. This greatly impacts traffic. Adaptive or dynamic sending rates based on user activity or data can also help, e.g. based on player latency.
  • Use unreliable messaging (e.g., WebRTC Data Channels and UDP) when possible. In many cases, unreliable messages are preferable as they do not require retransmission. For example, in an FPS, player positions can typically be sent unreliably.

Use Batched Operations

Batching operations is a good way to reduce the number of messages sent and avoid network overhead. This is especially useful for operations that are not time-critical.

Take a look at these methods which allows you to send multiple commands in one message:

  • $session.emit(commands, options = {})
  • $session.broadcast(commands, options = {})
  • $room.broadcast(commands, options = {})

API Reference

Example: Broadcasting within the current server:

javascript
$session.broadcast([
    {
        command: 'UpdatePlayer',
        params: {
            id: 101,
            x: 10,
            y: 25,
            state: 0
        }
    },
    {
        command: 'UpdateObject',
        params: {
            id: 5,
            rotation: 90
        }
    },
    ...
]);

Examples:

  • Broadcast a list of updates for different objects in one message.
  • Emit a list of commands to execute in one message.

Hard-code Room Settings

Storing room settings on the client side may significantly reduce network traffic as well.

How to export room settings?