Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perf: Rpc overhead #3925

Open
miwarnec opened this issue Oct 17, 2024 · 0 comments
Open

Perf: Rpc overhead #3925

miwarnec opened this issue Oct 17, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@miwarnec
Copy link
Collaborator

miwarnec commented Oct 17, 2024

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
@miwarnec miwarnec added the enhancement New feature or request label Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant