Named Messages: Don't allocate a byte array whenever you send a message
Los mantenedores suelen responder en 3 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 38/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Área
- networking, performance
Línea de trabajo
Empieza leyendo Runtime/Hashing/XXHash.cs y Runtime/Messaging/CustomMessageManager.cs, especialmente la ruta de llamada de SendNamedMessage y la asignación indicada en las líneas señaladas. Reproduce con el profiler la asignación de los mensajes con nombre y, a continuación, determina cómo evitarla manteniendo el comportamiento de hash de 32 bits y de 64 bits cuando cambie el tamaño de hash configurado. El trabajo estará terminado cuando los envíos con nombre ya no asignen el array de bytes del nombre y el comportamiento existente siga estando cubierto por las pruebas disponibles.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Is your feature request related to a problem? Please describe.
Named Messages are a great way to send custom messages that are not tied to a specific game object and/or are more dynamic than standard RPC calls. However, the only way to send these messages (via CustomMessagingManager.SendNamedMessage) is by providing a string which gets then hashed using XXHash.Hash32 or XXHash.Hash64 which then calls Encoding.UTF8.GetBytes(text). This function always allocates a new byte array, containing the string. As far as I can see, there is no other possible way to send a named message.
Describe the solution you'd like
I see two possible solutions:
- Don't use
Encoding.UTF8.GetBytes(text)and instead use one of the overloads where you can specify an existingbyte[]or Span. This would allow the use of a pre-alloced buffer (e.g. from a temp alloced NativeArray or an array pool). - Add a function overload where I can provide the hash myself (and provide a way to obtain this hash). This would work similar to e.g.
Animator.StringToHashorShader.PropertyToID. However, the HashSize can be 4 bytes or 8 bytes (depending onNetworkManager.NetworkConfig.RpcHashSize) and can even change during the runtime (at least,CustomMessageManagersupports this case). Therefore it might be a bit confusing to the user which hash (with which data type) they have to use in this case - unless theGetHashfunction returns a struct which contains both hashes...which might be a bit weird as well.
Describe alternatives you've considered
- I can use unnamed messages and just re-implement the logic from named messages, using the solution described above.
Additional context
Example GC Alloc from the profiler:
Size: 41
Call Stack:
mscorlib.dll!System.Text::Encoding.GetBytes()
Unity.Netcode.Runtime.dll!Unity.Netcode::XXHash.Hash32() ./Library/PackageCache/[email protected]/Runtime/Hashing/XXHash.cs:218
Unity.Netcode.Runtime.dll!Unity.Netcode::CustomMessagingManager.SendNamedMessage() ./Library/PackageCache/[email protected]/Runtime/Messaging/CustomMessageManager.cs:296
Unity.Netcode.Runtime.dll!Unity.Netcode::CustomMessagingManager.SendNamedMessageToAll() ./Library/PackageCache/[email protected]/Runtime/Messaging/CustomMessageManager.cs:236
I wouldn't say this is a huge problem (though it depends on how many messages are being sent and how long their name is), and unnamed messages are an easy workaround. However, most of this package seems to focus on allocating as little as possible, and I think that fixing this problem here shouldn't be too hard (otherwise just ignore this issue).
Thanks for your work on this amazing package, I really enjoy using it! I can also provide a PR with a fix mentioned above if you would like me to, I just didn't want to submit something unwanted.
- Lenguaje dominante
- C#
- Estrellas
- 2.3k
- Forks
- 465
- Merge medio
- 3 d 12 h
- PR fusionados (30 d)
- 39
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de Unity-Technologies/com.unity.netcode.gameobjects
-
TimeSyncMessage is sent reliably, so a late one resets the client clock backwards and stalls its NetworkTransformsPosiblemente ocupada @reginaldalfret la tomó hace 8 días. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 52/100
Unity-Technologies/com.unity.netcode.gameobjects#4249 ·
Los mantenedores suelen responder en 3 días
-
NetworkTransform: half-float base update dropped as out of order when UseUnreliableDeltas is on, so later deltas decode ~2 m offPosiblemente ocupada @NoelStephensUnity la tomó hace 8 días. Abiertoport:3.x-completed priority:medium stat:imported type:bug
Dificultad 4/5 3-5 días Aptitud para principiantes 57/100
Unity-Technologies/com.unity.netcode.gameobjects#4248 ·
Los mantenedores suelen responder en 3 días
-
Tracking type:feature-2.x
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
Unity-Technologies/com.unity.netcode.gameobjects#3870 · 5 comentarios ·
Los mantenedores suelen responder en 3 días
-
Please error, or at least warn, when a managed type is included in INetworkSerializeByMemcpyAbiertoTracking type:feature
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
Unity-Technologies/com.unity.netcode.gameobjects#3830 · 7 comentarios ·
Los mantenedores suelen responder en 3 días
-
priority:medium stat:imported type:feature type:feature-2.x
Dificultad 4/5 3-5 días Aptitud para principiantes 42/100
Unity-Technologies/com.unity.netcode.gameobjects#3706 · 5 comentarios ·
Los mantenedores suelen responder en 3 días
Todos los issues de Unity-Technologies/com.unity.netcode.gameobjects
Issues similares
-
hand-to-AI
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
CactuseSecurity/firewall-orchestrator#5803 ·
Los mantenedores suelen responder en 1 día
-
Typed MINID rejects numeric thresholds with a leading plus sign accepted by Redis and ValkeyAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
Los mantenedores suelen responder en 1 día
-
DXF with empty names failsAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 3 días
-
bug python
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
ilia-sokolov/OfficeAgent.NET#89 ·
Los mantenedores suelen responder en 13 días