-
Notifications
You must be signed in to change notification settings - Fork 455
chore: Improve performance of NetworkList
set operation
#3587
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
chore: Improve performance of NetworkList
set operation
#3587
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@@ -617,6 +617,13 @@ public T this[int index] | |||
} | |||
|
|||
var previousValue = m_List[index]; | |||
|
|||
// Compare the Value being applied to the current value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Comment why, not what. E.g. The CHANGELOG comment above would be good as a comment here instead, for example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As context, this was copied from the NetworkVariable
implementation. I agree the comment is somewhat self-evident and likely unnecessary.
Lines 156 to 158 in ce3b6d9
// Compare the Value being applied to the current value | |
if (!NetworkVariableSerialization<T>.AreEqual(ref m_InternalValue, ref value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…/com.unity.netcode.gameobjects into chore/network-list-performance-set-operation
continues: #3585
This PR adds an equality check to the
NetworkList<T>
indexer setter, aligning its behavior withNetworkVariable<T>.Value
. SinceNetworkList<T>
already constrainsT
toIEquatable<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
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