MirrorNetworking / MirrorNetworking/Mirror

Perf: Rpc overhead

Open
#3,925 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
C#
Stars
6.3k
Forks
870
PR merge metrics
No merged PRs in 30d

Description

Currently this is how RPCs are serialized and sent:

// server call:
RpcOnFire(42);

// RpcOnFire:
[ClientRpc]
void RpcOnFire(int value)
{
    NetworkWriterPooled writer = NetworkWriterPool.Get();                       // GET WRITER
    writer.WriteVarInt(value);                                                  // WRITE
    SendRPCInternal("RpcOnFire", -1182161215, writer, 0, includeOwner: true);
    NetworkWriterPool.Return(writer);
}

void SendRpcInternal()
{
    RpcMessage message = new RpcMessage
    {
        netId = netId,
        componentIndex = ComponentIndex,
        functionHash = (ushort)functionHashCode,
        payload = writer.ToArraySegment()                                       // ARRAYSEGMENT
    };

    using (NetworkWriterPooled serialized = NetworkWriterPool.Get())            // GET WRITER
    {
        // serialize once
        serialized.Write(message);                                              // WRITE
        // send to all observers
        foreach (NetworkConnectionToClient conn in netIdentity.observers.Values)
            conn.Send(message, channelId);
    }
}

Instead, we could do this:

WriteUInt(netId);
WriteByte(componentIndex)
WriteUShort(functionHash)
Write(serialized parameters) // weaver generated

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the shown RpcOnFire, SendRpcInternal, NetworkWriterPooled, RpcMessage, and NetworkConnectionToClient flow. Compare the current message serialization and observer-send path with the proposed direct layout, then identify the generated-serialization entry point. Done means RPC parameters are serialized directly with the netId, component index, and function hash without the described intermediate message and writer overhead.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
networking, performance
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.