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: reduce type resolution to find extension methods for serialization in NetworkBehaviourILPP #3224

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

ruccho
Copy link

@ruccho ruccho commented Feb 5, 2025

This PR will improve the performance of NetworkBehaviourILPP.

Currently, NetworkBehaviourILPP performs TypeReference resolutions for attribute and parameter types to find custom serialization methods in all referenced assemblies. It causes a read to the assembly containing the type if it has not been loaded yet.

We can skip the process earlier by first filtering methods with only the information we can get without TypeDefinition.

Measurement

With minimalproject, I used the following code for measurement.

diff --git a/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs b/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs
index 7e95fea9..39b4f991 100644
--- a/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs
+++ b/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs
@@ -77,6 +77,8 @@ namespace Unity.Netcode.Editor.CodeGen
 
             m_Diagnostics.Clear();
 
+            var sw = System.Diagnostics.Stopwatch.StartNew();
+
             // read
             var assemblyDefinition = CodeGenHelpers.AssemblyDefinitionFor(compiledAssembly, out m_AssemblyResolver);
             if (assemblyDefinition == null)
@@ -171,6 +173,8 @@ namespace Unity.Netcode.Editor.CodeGen
 
             assemblyDefinition.Write(pe, writerParameters);
 
+            m_Diagnostics.AddWarning($"ILPP has completed for {compiledAssembly.Name} in {sw.ElapsedMilliseconds} ms");
+
             return new ILPostProcessResult(new InMemoryAssembly(pe.ToArray(), pdb.ToArray()), m_Diagnostics);
         }
 

Before

(0,0): warning  - ILPP has completed for Unity.Netcode.Editor in 531 ms
(0,0): warning  - ILPP has completed for Unity.Netcode.EditorTests in 604 ms
(0,0): warning  - ILPP has completed for Unity.Netcode.Components in 363 ms
(0,0): warning  - ILPP has completed for Unity.Netcode.TestHelpers.Runtime in 330 ms
(0,0): warning  - ILPP has completed for Unity.Netcode.RuntimeTests in 735 ms

After

(0,0): warning  - ILPP has completed for Unity.Netcode.Editor in 79 ms
(0,0): warning  - ILPP has completed for Unity.Netcode.EditorTests in 128 ms
(0,0): warning  - ILPP has completed for Unity.Netcode.Components in 146 ms
(0,0): warning  - ILPP has completed for Unity.Netcode.TestHelpers.Runtime in 117 ms
(0,0): warning  - ILPP has completed for Unity.Netcode.RuntimeTests in 537 ms

Changelog

  • Changed: Improved performance of NetworkBehaviour ILPostProcessor by omitting unnecessary type and assembly resolutions.

Testing and Documentation

  • No tests have been added.
  • No documentation changes or additions were necessary.

@ruccho ruccho requested a review from a team as a code owner February 5, 2025 07:28
@unity-cla-assistant
Copy link

unity-cla-assistant commented Feb 5, 2025

CLA assistant check
All committers have signed the CLA.

@NoelStephensUnity
Copy link
Collaborator

@ruccho
Looks promising and I will be getting this into a draft PR that can be reviewed further.
Thank you for your contribution!

@NoelStephensUnity
Copy link
Collaborator

@ruccho

Running this through our CI tests exposes a bunch of issues:

Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1060,13): error  - SendMySharedObjectReferencedByIdServerRpc - Don't know how to serialize TestProject.RuntimeTests.MySharedObjectReferencedById. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace TestProject.RuntimeTests.MySharedObjectReferencedById with ForceNetworkSerializeByMemcpy`1<TestProject.RuntimeTests.MySharedObjectReferencedById>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out TestProject.RuntimeTests.MySharedObjectReferencedById) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in TestProject.RuntimeTests.MySharedObjectReferencedById) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1060,13): error  - SendMySharedObjectReferencedByIdServerRpc - Don't know how to deserialize TestProject.RuntimeTests.MySharedObjectReferencedById. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace TestProject.RuntimeTests.MySharedObjectReferencedById with ForceNetworkSerializeByMemcpy`1<TestProject.RuntimeTests.MySharedObjectReferencedById>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out TestProject.RuntimeTests.MySharedObjectReferencedById) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in TestProject.RuntimeTests.MySharedObjectReferencedById) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1162,13): error  - SendMyObjectClientRpc - Don't know how to serialize TestProject.RuntimeTests.MyObject[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace TestProject.RuntimeTests.MyObject[] with ForceNetworkSerializeByMemcpy`1<TestProject.RuntimeTests.MyObject[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out TestProject.RuntimeTests.MyObject[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in TestProject.RuntimeTests.MyObject[]) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1162,13): error  - SendMyObjectClientRpc - Don't know how to deserialize TestProject.RuntimeTests.MyObject[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace TestProject.RuntimeTests.MyObject[] with ForceNetworkSerializeByMemcpy`1<TestProject.RuntimeTests.MyObject[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out TestProject.RuntimeTests.MyObject[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in TestProject.RuntimeTests.MyObject[]) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1168,13): error  - SendIntListClientRpc - Don't know how to serialize System.Collections.Generic.List`1<System.Int32>[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace System.Collections.Generic.List`1<System.Int32>[] with ForceNetworkSerializeByMemcpy`1<System.Collections.Generic.List`1<System.Int32>[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out System.Collections.Generic.List`1<System.Int32>[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in System.Collections.Generic.List`1<System.Int32>[]) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1168,13): error  - SendIntListClientRpc - Don't know how to deserialize System.Collections.Generic.List`1<System.Int32>[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace System.Collections.Generic.List`1<System.Int32>[] with ForceNetworkSerializeByMemcpy`1<System.Collections.Generic.List`1<System.Int32>[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out System.Collections.Generic.List`1<System.Int32>[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in System.Collections.Generic.List`1<System.Int32>[]) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1174,13): error  - SendStringListClientRpc - Don't know how to serialize System.Collections.Generic.List`1<System.String>[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace System.Collections.Generic.List`1<System.String>[] with ForceNetworkSerializeByMemcpy`1<System.Collections.Generic.List`1<System.String>[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out System.Collections.Generic.List`1<System.String>[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in System.Collections.Generic.List`1<System.String>[]) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1174,13): error  - SendStringListClientRpc - Don't know how to deserialize System.Collections.Generic.List`1<System.String>[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace System.Collections.Generic.List`1<System.String>[] with ForceNetworkSerializeByMemcpy`1<System.Collections.Generic.List`1<System.String>[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out System.Collections.Generic.List`1<System.String>[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in System.Collections.Generic.List`1<System.String>[]) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1186,13): error  - SendMySharedObjectReferencedByIdClientRpc - Don't know how to serialize TestProject.RuntimeTests.MySharedObjectReferencedById[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace TestProject.RuntimeTests.MySharedObjectReferencedById[] with ForceNetworkSerializeByMemcpy`1<TestProject.RuntimeTests.MySharedObjectReferencedById[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out TestProject.RuntimeTests.MySharedObjectReferencedById[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in TestProject.RuntimeTests.MySharedObjectReferencedById[]) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1186,13): error  - SendMySharedObjectReferencedByIdClientRpc - Don't know how to deserialize TestProject.RuntimeTests.MySharedObjectReferencedById[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace TestProject.RuntimeTests.MySharedObjectReferencedById[] with ForceNetworkSerializeByMemcpy`1<TestProject.RuntimeTests.MySharedObjectReferencedById[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out TestProject.RuntimeTests.MySharedObjectReferencedById[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in TestProject.RuntimeTests.MySharedObjectReferencedById[]) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1192,13): error  - SendMyObjectServerRpc - Don't know how to serialize TestProject.RuntimeTests.MyObject[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace TestProject.RuntimeTests.MyObject[] with ForceNetworkSerializeByMemcpy`1<TestProject.RuntimeTests.MyObject[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out TestProject.RuntimeTests.MyObject[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in TestProject.RuntimeTests.MyObject[]) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1192,13): error  - SendMyObjectServerRpc - Don't know how to deserialize TestProject.RuntimeTests.MyObject[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace TestProject.RuntimeTests.MyObject[] with ForceNetworkSerializeByMemcpy`1<TestProject.RuntimeTests.MyObject[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out TestProject.RuntimeTests.MyObject[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in TestProject.RuntimeTests.MyObject[]) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1199,13): error  - SendIntListServerRpc - Don't know how to serialize System.Collections.Generic.List`1<System.Int32>[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace System.Collections.Generic.List`1<System.Int32>[] with ForceNetworkSerializeByMemcpy`1<System.Collections.Generic.List`1<System.Int32>[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out System.Collections.Generic.List`1<System.Int32>[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in System.Collections.Generic.List`1<System.Int32>[]) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1199,13): error  - SendIntListServerRpc - Don't know how to deserialize System.Collections.Generic.List`1<System.Int32>[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace System.Collections.Generic.List`1<System.Int32>[] with ForceNetworkSerializeByMemcpy`1<System.Collections.Generic.List`1<System.Int32>[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out System.Collections.Generic.List`1<System.Int32>[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in System.Collections.Generic.List`1<System.Int32>[]) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1206,13): error  - SendStringListServerRpc - Don't know how to serialize System.Collections.Generic.List`1<System.String>[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace System.Collections.Generic.List`1<System.String>[] with ForceNetworkSerializeByMemcpy`1<System.Collections.Generic.List`1<System.String>[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out System.Collections.Generic.List`1<System.String>[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in System.Collections.Generic.List`1<System.String>[]) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1206,13): error  - SendStringListServerRpc - Don't know how to deserialize System.Collections.Generic.List`1<System.String>[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace System.Collections.Generic.List`1<System.String>[] with ForceNetworkSerializeByMemcpy`1<System.Collections.Generic.List`1<System.String>[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out System.Collections.Generic.List`1<System.String>[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in System.Collections.Generic.List`1<System.String>[]) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1221,13): error  - SendMySharedObjectReferencedByIdServerRpc - Don't know how to serialize TestProject.RuntimeTests.MySharedObjectReferencedById[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace TestProject.RuntimeTests.MySharedObjectReferencedById[] with ForceNetworkSerializeByMemcpy`1<TestProject.RuntimeTests.MySharedObjectReferencedById[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out TestProject.RuntimeTests.MySharedObjectReferencedById[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in TestProject.RuntimeTests.MySharedObjectReferencedById[]) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1221,13): error  - SendMySharedObjectReferencedByIdServerRpc - Don't know how to deserialize TestProject.RuntimeTests.MySharedObjectReferencedById[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace TestProject.RuntimeTests.MySharedObjectReferencedById[] with ForceNetworkSerializeByMemcpy`1<TestProject.RuntimeTests.MySharedObjectReferencedById[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out TestProject.RuntimeTests.MySharedObjectReferencedById[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in TestProject.RuntimeTests.MySharedObjectReferencedById[]) to define serialization for this type.
*** Tundra build failed (33.34 seconds), 784 items updated, 787 evaluated
[16:26:32.034 Information] Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1005,13): error  - SendMyObjectClientRpc - Don't know how to serialize TestProject.RuntimeTests.MyObject. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace TestProject.RuntimeTests.MyObject with ForceNetworkSerializeByMemcpy`1<TestProject.RuntimeTests.MyObject>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out TestProject.RuntimeTests.MyObject) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in TestProject.RuntimeTests.MyObject) to define serialization for this type.
[16:26:32.039 Information] Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1005,13): error  - SendMyObjectClientRpc - Don't know how to deserialize TestProject.RuntimeTests.MyObject. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace TestProject.RuntimeTests.MyObject with ForceNetworkSerializeByMemcpy`1<TestProject.RuntimeTests.MyObject>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out TestProject.RuntimeTests.MyObject) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in TestProject.RuntimeTests.MyObject) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1010,13): error  - SendIntListClientRpc - Don't know how to serialize System.Collections.Generic.List`1<System.Int32>. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace System.Collections.Generic.List`1<System.Int32> with ForceNetworkSerializeByMemcpy`1<System.Collections.Generic.List`1<System.Int32>>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out System.Collections.Generic.List`1<System.Int32>) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in System.Collections.Generic.List`1<System.Int32>) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1010,13): error  - SendIntListClientRpc - Don't know how to deserialize System.Collections.Generic.List`1<System.Int32>. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace System.Collections.Generic.List`1<System.Int32> with ForceNetworkSerializeByMemcpy`1<System.Collections.Generic.List`1<System.Int32>>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out System.Collections.Generic.List`1<System.Int32>) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in System.Collections.Generic.List`1<System.Int32>) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1015,13): error  - SendStringListClientRpc - Don't know how to serialize System.Collections.Generic.List`1<System.String>. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace System.Collections.Generic.List`1<System.String> with ForceNetworkSerializeByMemcpy`1<System.Collections.Generic.List`1<System.String>>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out System.Collections.Generic.List`1<System.String>) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in System.Collections.Generic.List`1<System.String>) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1015,13): error  - SendStringListClientRpc - Don't know how to deserialize System.Collections.Generic.List`1<System.String>. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace System.Collections.Generic.List`1<System.String> with ForceNetworkSerializeByMemcpy`1<System.Collections.Generic.List`1<System.String>>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out System.Collections.Generic.List`1<System.String>) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in System.Collections.Generic.List`1<System.String>) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1026,13): error  - SendMySharedObjectReferencedByIdClientRpc - Don't know how to serialize TestProject.RuntimeTests.MySharedObjectReferencedById. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace TestProject.RuntimeTests.MySharedObjectReferencedById with ForceNetworkSerializeByMemcpy`1<TestProject.RuntimeTests.MySharedObjectReferencedById>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out TestProject.RuntimeTests.MySharedObjectReferencedById) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in TestProject.RuntimeTests.MySharedObjectReferencedById) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1026,13): error  - SendMySharedObjectReferencedByIdClientRpc - Don't know how to deserialize TestProject.RuntimeTests.MySharedObjectReferencedById. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace TestProject.RuntimeTests.MySharedObjectReferencedById with ForceNetworkSerializeByMemcpy`1<TestProject.RuntimeTests.MySharedObjectReferencedById>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out TestProject.RuntimeTests.MySharedObjectReferencedById) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in TestProject.RuntimeTests.MySharedObjectReferencedById) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1032,13): error  - SendMyObjectServerRpc - Don't know how to serialize TestProject.RuntimeTests.MyObject. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace TestProject.RuntimeTests.MyObject with ForceNetworkSerializeByMemcpy`1<TestProject.RuntimeTests.MyObject>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out TestProject.RuntimeTests.MyObject) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in TestProject.RuntimeTests.MyObject) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1032,13): error  - SendMyObjectServerRpc - Don't know how to deserialize TestProject.RuntimeTests.MyObject. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace TestProject.RuntimeTests.MyObject with ForceNetworkSerializeByMemcpy`1<TestProject.RuntimeTests.MyObject>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out TestProject.RuntimeTests.MyObject) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in TestProject.RuntimeTests.MyObject) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1039,13): error  - SendIntListServerRpc - Don't know how to serialize System.Collections.Generic.List`1<System.Int32>. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace System.Collections.Generic.List`1<System.Int32> with ForceNetworkSerializeByMemcpy`1<System.Collections.Generic.List`1<System.Int32>>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out System.Collections.Generic.List`1<System.Int32>) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in System.Collections.Generic.List`1<System.Int32>) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1039,13): error  - SendIntListServerRpc - Don't know how to deserialize System.Collections.Generic.List`1<System.Int32>. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace System.Collections.Generic.List`1<System.Int32> with ForceNetworkSerializeByMemcpy`1<System.Collections.Generic.List`1<System.Int32>>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out System.Collections.Generic.List`1<System.Int32>) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in System.Collections.Generic.List`1<System.Int32>) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1046,13): error  - SendStringListServerRpc - Don't know how to serialize System.Collections.Generic.List`1<System.String>. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace System.Collections.Generic.List`1<System.String> with ForceNetworkSerializeByMemcpy`1<System.Collections.Generic.List`1<System.String>>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out System.Collections.Generic.List`1<System.String>) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in System.Collections.Generic.List`1<System.String>) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1046,13): error  - SendStringListServerRpc - Don't know how to deserialize System.Collections.Generic.List`1<System.String>. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace System.Collections.Generic.List`1<System.String> with ForceNetworkSerializeByMemcpy`1<System.Collections.Generic.List`1<System.String>>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out System.Collections.Generic.List`1<System.String>) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in System.Collections.Generic.List`1<System.String>) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1060,13): error  - SendMySharedObjectReferencedByIdServerRpc - Don't know how to serialize TestProject.RuntimeTests.MySharedObjectReferencedById. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace TestProject.RuntimeTests.MySharedObjectReferencedById with ForceNetworkSerializeByMemcpy`1<TestProject.RuntimeTests.MySharedObjectReferencedById>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out TestProject.RuntimeTests.MySharedObjectReferencedById) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in TestProject.RuntimeTests.MySharedObjectReferencedById) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1060,13): error  - SendMySharedObjectReferencedByIdServerRpc - Don't know how to deserialize TestProject.RuntimeTests.MySharedObjectReferencedById. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace TestProject.RuntimeTests.MySharedObjectReferencedById with ForceNetworkSerializeByMemcpy`1<TestProject.RuntimeTests.MySharedObjectReferencedById>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out TestProject.RuntimeTests.MySharedObjectReferencedById) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in TestProject.RuntimeTests.MySharedObjectReferencedById) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1162,13): error  - SendMyObjectClientRpc - Don't know how to serialize TestProject.RuntimeTests.MyObject[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace TestProject.RuntimeTests.MyObject[] with ForceNetworkSerializeByMemcpy`1<TestProject.RuntimeTests.MyObject[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out TestProject.RuntimeTests.MyObject[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in TestProject.RuntimeTests.MyObject[]) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1162,13): error  - SendMyObjectClientRpc - Don't know how to deserialize TestProject.RuntimeTests.MyObject[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace TestProject.RuntimeTests.MyObject[] with ForceNetworkSerializeByMemcpy`1<TestProject.RuntimeTests.MyObject[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out TestProject.RuntimeTests.MyObject[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in TestProject.RuntimeTests.MyObject[]) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1168,13): error  - SendIntListClientRpc - Don't know how to serialize System.Collections.Generic.List`1<System.Int32>[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace System.Collections.Generic.List`1<System.Int32>[] with ForceNetworkSerializeByMemcpy`1<System.Collections.Generic.List`1<System.Int32>[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out System.Collections.Generic.List`1<System.Int32>[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in System.Collections.Generic.List`1<System.Int32>[]) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1168,13): error  - SendIntListClientRpc - Don't know how to deserialize System.Collections.Generic.List`1<System.Int32>[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace System.Collections.Generic.List`1<System.Int32>[] with ForceNetworkSerializeByMemcpy`1<System.Collections.Generic.List`1<System.Int32>[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out System.Collections.Generic.List`1<System.Int32>[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in System.Collections.Generic.List`1<System.Int32>[]) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1174,13): error  - SendStringListClientRpc - Don't know how to serialize System.Collections.Generic.List`1<System.String>[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace System.Collections.Generic.List`1<System.String>[] with ForceNetworkSerializeByMemcpy`1<System.Collections.Generic.List`1<System.String>[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out System.Collections.Generic.List`1<System.String>[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in System.Collections.Generic.List`1<System.String>[]) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1174,13): error  - SendStringListClientRpc - Don't know how to deserialize System.Collections.Generic.List`1<System.String>[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace System.Collections.Generic.List`1<System.String>[] with ForceNetworkSerializeByMemcpy`1<System.Collections.Generic.List`1<System.String>[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out System.Collections.Generic.List`1<System.String>[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in System.Collections.Generic.List`1<System.String>[]) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1186,13): error  - SendMySharedObjectReferencedByIdClientRpc - Don't know how to serialize TestProject.RuntimeTests.MySharedObjectReferencedById[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace TestProject.RuntimeTests.MySharedObjectReferencedById[] with ForceNetworkSerializeByMemcpy`1<TestProject.RuntimeTests.MySharedObjectReferencedById[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out TestProject.RuntimeTests.MySharedObjectReferencedById[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in TestProject.RuntimeTests.MySharedObjectReferencedById[]) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1186,13): error  - SendMySharedObjectReferencedByIdClientRpc - Don't know how to deserialize TestProject.RuntimeTests.MySharedObjectReferencedById[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace TestProject.RuntimeTests.MySharedObjectReferencedById[] with ForceNetworkSerializeByMemcpy`1<TestProject.RuntimeTests.MySharedObjectReferencedById[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out TestProject.RuntimeTests.MySharedObjectReferencedById[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in TestProject.RuntimeTests.MySharedObjectReferencedById[]) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1192,13): error  - SendMyObjectServerRpc - Don't know how to serialize TestProject.RuntimeTests.MyObject[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace TestProject.RuntimeTests.MyObject[] with ForceNetworkSerializeByMemcpy`1<TestProject.RuntimeTests.MyObject[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out TestProject.RuntimeTests.MyObject[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in TestProject.RuntimeTests.MyObject[]) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1192,13): error  - SendMyObjectServerRpc - Don't know how to deserialize TestProject.RuntimeTests.MyObject[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace TestProject.RuntimeTests.MyObject[] with ForceNetworkSerializeByMemcpy`1<TestProject.RuntimeTests.MyObject[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out TestProject.RuntimeTests.MyObject[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in TestProject.RuntimeTests.MyObject[]) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1199,13): error  - SendIntListServerRpc - Don't know how to serialize System.Collections.Generic.List`1<System.Int32>[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace System.Collections.Generic.List`1<System.Int32>[] with ForceNetworkSerializeByMemcpy`1<System.Collections.Generic.List`1<System.Int32>[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out System.Collections.Generic.List`1<System.Int32>[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in System.Collections.Generic.List`1<System.Int32>[]) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1199,13): error  - SendIntListServerRpc - Don't know how to deserialize System.Collections.Generic.List`1<System.Int32>[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace System.Collections.Generic.List`1<System.Int32>[] with ForceNetworkSerializeByMemcpy`1<System.Collections.Generic.List`1<System.Int32>[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out System.Collections.Generic.List`1<System.Int32>[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in System.Collections.Generic.List`1<System.Int32>[]) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1206,13): error  - SendStringListServerRpc - Don't know how to serialize System.Collections.Generic.List`1<System.String>[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace System.Collections.Generic.List`1<System.String>[] with ForceNetworkSerializeByMemcpy`1<System.Collections.Generic.List`1<System.String>[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out System.Collections.Generic.List`1<System.String>[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in System.Collections.Generic.List`1<System.String>[]) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1206,13): error  - SendStringListServerRpc - Don't know how to deserialize System.Collections.Generic.List`1<System.String>[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace System.Collections.Generic.List`1<System.String>[] with ForceNetworkSerializeByMemcpy`1<System.Collections.Generic.List`1<System.String>[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out System.Collections.Generic.List`1<System.String>[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in System.Collections.Generic.List`1<System.String>[]) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1221,13): error  - SendMySharedObjectReferencedByIdServerRpc - Don't know how to serialize TestProject.RuntimeTests.MySharedObjectReferencedById[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace TestProject.RuntimeTests.MySharedObjectReferencedById[] with ForceNetworkSerializeByMemcpy`1<TestProject.RuntimeTests.MySharedObjectReferencedById[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out TestProject.RuntimeTests.MySharedObjectReferencedById[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in TestProject.RuntimeTests.MySharedObjectReferencedById[]) to define serialization for this type.
Assets/Tests/Runtime/RpcUserSerializableTypesTest.cs(1221,13): error  - SendMySharedObjectReferencedByIdServerRpc - Don't know how to deserialize TestProject.RuntimeTests.MySharedObjectReferencedById[]. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace TestProject.RuntimeTests.MySharedObjectReferencedById[] with ForceNetworkSerializeByMemcpy`1<TestProject.RuntimeTests.MySharedObjectReferencedById[]>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out TestProject.RuntimeTests.MySharedObjectReferencedById[]) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in TestProject.RuntimeTests.MySharedObjectReferencedById[]) to define serialization for this type.

I liked the direction you were going with this, but it seems that some of your proposed optimizations cause ILPP to miss processing specific types/classes.

@ruccho
Copy link
Author

ruccho commented Feb 6, 2025

@NoelStephensUnity
I overlooked that ReadValueSafe / WriteValueSafe can accept FastBufferReader / FastBufferWriter by reference or by value.

static void ReadValueSafe(this FastBufferReader reader, out T value)
static void ReadValueSafe(this ref FastBufferReader reader, out T value)

I think I was able to fix it. Could you please try again?

@NoelStephensUnity
Copy link
Collaborator

@NoelStephensUnity I overlooked that ReadValueSafe / WriteValueSafe can accept FastBufferReader / FastBufferWriter by reference or by value.

static void ReadValueSafe(this FastBufferReader reader, out T value)
static void ReadValueSafe(this ref FastBufferReader reader, out T value)

I think I was able to fix it. Could you please try again?

Running with the updates.
👍

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.

3 participants