perf: Optimize NetworkList indexer setter performance#3585
perf: Optimize NetworkList indexer setter performance#3585harayuu9 wants to merge 2 commits intoUnity-Technologies:develop-2.0.0from
Conversation
…nged Added equality check in NetworkList indexer setter to avoid unnecessary operations when the new value equals the existing value. This improves performance by preventing redundant list events and network synchronization.
EmandM
left a comment
There was a problem hiding this comment.
Thanks again for the submission! This seems like a fantastic and needed optimization. I'll pull this over internally.
In case you didn't know, it's now possible to use Collections inside of NetworkVariables. So you can use NetworkVariable<CollectionType> and NGO will use network optimized deltas for the network variable updates (docs).
We're super interested if you have any feedback on the usage of NetworkList<T> vs NetworkVariable<List<T>>.
|
@EmandM Another important factor is that |
|
Cheers for the feedback! It's great to have performance improvements that are based on real-life use-cases. We'll land this fix over in #3587 |
continues: #3585 This PR adds an equality check to the `NetworkList<T>` indexer setter, aligning its behavior with `NetworkVariable<T>.Value`. Since `NetworkList<T>` already constrains `T` to `IEquatable<T>`, this change is both safe and broadly applicable. It avoids redundant assignments when the new value is equal to the current value, which improves runtime efficiency and avoids unnecessary event dispatch and network synchronization. ## Changelog - Changed: Optimized `NetworkList<T>` indexer setter to skip operations when the new value equals the existing value, improving performance by avoiding unnecessary list events and network synchronization. ## Testing & QA This is a very small optimization in an area of code that is deeply covered by unit and integration tests. No manual testing is required. ## Documentation As there are no API or behaviour changes, no documentation is required ## Backport This is a new optimization and so doesn't need to be backported --------- Co-authored-by: Yuto Harada <yuto.harada@polyscape.io>
This PR adds an equality check to the
NetworkList<T>indexer setter, aligning its behavior withNetworkVariable<T>.Value. SinceNetworkList<T>already constrainsTtoIEquatable<T>, this change is both safe and broadly applicable. It avoids redundant assignments when the new value is equal to the current value, which improves runtime efficiency and avoids unnecessary event dispatch and network synchronization.Changelog
com.unity.netcode.gameobjects
NetworkList<T>indexer setter to skip operations when the new value equals the existing value, improving performance by avoiding unnecessary list events and network synchronization.Testing and Documentation
Backport
Not applicable.