Skip to content

refactor: Splitting MessagingSystem.SendMessage into a second part … #1642

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

Merged
merged 4 commits into from
Feb 2, 2022

Conversation

jeffreyrainy
Copy link
Contributor

SendPreSerializedMessage. This allows SnapshotSystem to send larger messages, while saving an allocation and a copy.

…alizedMessage. This allows SnapshotSystem to send larger messages, while saving an allocation and a copy.
@@ -919,8 +919,7 @@ internal void NetworkGetBehaviourVariable(UpdateCommand updateCommand, out Netwo

internal int NetworkSendMessage(SnapshotDataMessage message, ulong clientId)
{
m_NetworkManager.SendMessage(ref message, NetworkDelivery.ReliableFragmentedSequenced, clientId);

m_NetworkManager.SendPreSerializedMessage(message.WriteBuffer, TotalBufferMemory, ref message, NetworkDelivery.Unreliable, clientId);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This simply calls a bit further in, after tmpSerializer, because we happen to have such a FastBufferWriter ready.

@@ -352,7 +352,7 @@ private bool CanSend(ulong clientId, Type messageType, NetworkDelivery delivery)
return true;
}

internal unsafe int SendMessage<TMessageType, TClientIdListType>(ref TMessageType message, NetworkDelivery delivery, in TClientIdListType clientIds)
internal int SendMessage<TMessageType, TClientIdListType>(ref TMessageType message, NetworkDelivery delivery, in TClientIdListType clientIds)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simply split the function in two parts. The first part doesn't need the unsafe keyword anymore

@@ -426,6 +432,13 @@ private bool CanSend(ulong clientId, Type messageType, NetworkDelivery delivery)
return tmpSerializer.Length + headerSerializer.Length;
}

internal unsafe int SendPreSerializedMessage<TMessageType>(in FastBufferWriter tmpSerializer, int maxSize, ref TMessageType message, NetworkDelivery delivery, ulong clientId)
Copy link
Contributor Author

@jeffreyrainy jeffreyrainy Feb 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds an entrypoint taking a single clientId instead of a PointerListWrapper, because that class is private.

…dPreSerializedMessage. This allows SnapshotSystem to send larger messages, while saving an allocation and a copy.
…ty-Technologies/com.unity.multiplayer.mlapi into refactor/send-message-pre-serialized
Copy link
Contributor

@0xFA11 0xFA11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@jeffreyrainy jeffreyrainy merged commit 23ac017 into develop Feb 2, 2022
@jeffreyrainy jeffreyrainy deleted the refactor/send-message-pre-serialized branch February 2, 2022 17:28
jeffreyrainy added a commit that referenced this pull request Feb 16, 2022
…1642)

* Splitting MessagingSystem.SendMessage into a second part, SendPreSerializedMessage. This allows SnapshotSystem to send larger messages, while saving an allocation and a copy.

* refactor: Splitting MessagingSystem.SendMessage into second part, SendPreSerializedMessage. This allows SnapshotSystem to send larger messages, while saving an allocation and a copy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants