From 0d80039041d477f9865f5f9f65c601eb8c708a67 Mon Sep 17 00:00:00 2001 From: Yuto Harada Date: Wed, 6 Aug 2025 16:44:47 +0900 Subject: [PATCH 1/4] perf(networked-vars): Skip NetworkList set operation when value unchanged 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. --- .../Runtime/NetworkVariable/Collections/NetworkList.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs index 9f0382c26a..e47b92e9b2 100644 --- a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs +++ b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs @@ -617,6 +617,13 @@ public T this[int index] } var previousValue = m_List[index]; + + // Compare the Value being applied to the current value + if (NetworkVariableSerialization.AreEqual(ref previousValue, ref value)) + { + return; + } + m_List[index] = value; var listEvent = new NetworkListEvent() From d2ed595a65f6e6d68bf69627b2026227a23adda2 Mon Sep 17 00:00:00 2001 From: Yuto Harada Date: Wed, 6 Aug 2025 16:47:47 +0900 Subject: [PATCH 2/4] docs: Add CHANGELOG entry for NetworkList optimization (#????) --- com.unity.netcode.gameobjects/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/com.unity.netcode.gameobjects/CHANGELOG.md b/com.unity.netcode.gameobjects/CHANGELOG.md index ce3051ca2e..0c77b0e77c 100644 --- a/com.unity.netcode.gameobjects/CHANGELOG.md +++ b/com.unity.netcode.gameobjects/CHANGELOG.md @@ -19,6 +19,8 @@ Additional documentation and release notes are available at [Multiplayer Documen ### Changed +- Optimized `NetworkList` indexer setter to skip operations when the new value equals the existing value, improving performance by avoiding unnecessary list events and network synchronization. (#????) + ## [2.5.0] - 2025-08-01 From ee1d602491d6f5df72e5c6b9fd52915de74389f6 Mon Sep 17 00:00:00 2001 From: Emma Date: Wed, 6 Aug 2025 16:06:28 -0400 Subject: [PATCH 3/4] Update CHANGELOG --- com.unity.netcode.gameobjects/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.netcode.gameobjects/CHANGELOG.md b/com.unity.netcode.gameobjects/CHANGELOG.md index 0c77b0e77c..0e1bbc0de0 100644 --- a/com.unity.netcode.gameobjects/CHANGELOG.md +++ b/com.unity.netcode.gameobjects/CHANGELOG.md @@ -19,7 +19,7 @@ Additional documentation and release notes are available at [Multiplayer Documen ### Changed -- Optimized `NetworkList` indexer setter to skip operations when the new value equals the existing value, improving performance by avoiding unnecessary list events and network synchronization. (#????) +- Optimized `NetworkList` indexer setter to skip operations when the new value equals the existing value, improving performance by avoiding unnecessary list events and network synchronization. (#3587) ## [2.5.0] - 2025-08-01 From 7b8e5e18899420153107cb584141dfb3c0e2a46c Mon Sep 17 00:00:00 2001 From: Emma Date: Thu, 7 Aug 2025 13:20:10 -0400 Subject: [PATCH 4/4] Update code comment to match context --- .../Runtime/NetworkVariable/Collections/NetworkList.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs index e47b92e9b2..c7c2554d21 100644 --- a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs +++ b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs @@ -618,7 +618,7 @@ public T this[int index] var previousValue = m_List[index]; - // Compare the Value being applied to the current value + // Only trigger an event if the value has changed if (NetworkVariableSerialization.AreEqual(ref previousValue, ref value)) { return;