Named Messages: Don't allocate a byte array whenever you send a message
I maintainer di solito rispondono entro 3 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 38/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Ambito
- networking, performance
Direzione di ricerca
Inizia leggendo Runtime/Hashing/XXHash.cs e Runtime/Messaging/CustomMessageManager.cs, in particolare il percorso di chiamata di SendNamedMessage e l’allocazione indicata alle righe segnalate. Riproduci con il profiler l’allocazione dei messaggi denominati, quindi determina come evitarla preservando sia il comportamento dell’hash a 32 bit sia quello a 64 bit quando cambia la dimensione dell’hash configurata. Il lavoro è completato quando gli invii denominati non allocano più l’array di byte del nome e il comportamento esistente continua a essere coperto dai test disponibili.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- C#
- Stelle
- 2.3k
- Fork
- 465
- Merge medio
- 3g 12h
- PR unite (30g)
- 39
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Unity-Technologies/com.unity.netcode.gameobjects
-
TimeSyncMessage is sent reliably, so a late one resets the client clock backwards and stalls its NetworkTransformsForse già presa @reginaldalfret l’ha presa 8 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
Unity-Technologies/com.unity.netcode.gameobjects#4249 ·
I maintainer di solito rispondono entro 3 giorni
-
NetworkTransform: half-float base update dropped as out of order when UseUnreliableDeltas is on, so later deltas decode ~2 m offForse già presa @NoelStephensUnity l’ha presa 8 giorni fa. Apertaport:3.x-completed priority:medium stat:imported type:bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 57/100
Unity-Technologies/com.unity.netcode.gameobjects#4248 ·
I maintainer di solito rispondono entro 3 giorni
-
Tracking type:feature-2.x
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
Unity-Technologies/com.unity.netcode.gameobjects#3870 · 5 commenti ·
I maintainer di solito rispondono entro 3 giorni
-
Tracking type:feature
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
Unity-Technologies/com.unity.netcode.gameobjects#3830 · 7 commenti ·
I maintainer di solito rispondono entro 3 giorni
-
priority:medium stat:imported type:feature type:feature-2.x
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
Unity-Technologies/com.unity.netcode.gameobjects#3706 · 5 commenti ·
I maintainer di solito rispondono entro 3 giorni
Tutte le issue di Unity-Technologies/com.unity.netcode.gameobjects
Issue simili
-
DXF with empty names failsApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 3 giorni
-
bug python
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
ilia-sokolov/OfficeAgent.NET#89 ·
I maintainer di solito rispondono entro 13 giorni
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
juandresrodca/AdminForge#66 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
umbraco/Umbraco.Automate#612 ·
I maintainer di solito rispondono entro 1 giorno