Skip to content

Conversation

@samlucas-unity
Copy link
Contributor

@samlucas-unity samlucas-unity commented Jun 27, 2025

Fix for MTTB-85 removed the use of a foreach causing an unnecessary GC Allocation.

Did a full sweep of internal NetworkManager.ConnectedClientsIds and replaced with either for loop or directly referencing the NetworkConnectionManager.ConnectedClientIds.

Changelog

  • Fixed: Issue with unnecessary internal GC Allocations when using the IReadOnlyList NetworkManager.ConnectedClientsIds within a foreach statement by either replacing with a for loop or directly referencing the NetworkConnectionManager.ConnectedClientIds.

Documentation

  • No documentation updates were required.

Testing & QA

Functional Testing

Manual testing :

  • Manual testing done
    • Tested manually before and after fix to confirm the allocation was present and then absent.

Automated tests:

  • Covered by existing automated tests
  • Covered by new automated tests

Does the change require QA team to:

  • Review automated tests?
  • Execute manual tests?

If any boxes above are checked, please add QA as a PR reviewer.

Backport

The backport of this PR is #3601

@michalChrobot
Copy link
Collaborator

Do you know if this is only 2.X specific or should also be backported to 1.X (develop branch)?

Doing a full pass on the internal usage of NetworkManager.ConnectedClientsIds and replacing with NetworkConnectionManager.ConnectedClientIds to remove any other potential small memory allocations.
The best savings will be where it is used in universal RPCs.
@NoelStephensUnity
Copy link
Collaborator

Do you know if this is only 2.X specific or should also be backported to 1.X (develop branch)?

Portions of this PR could be back ported to v1.x.

@NoelStephensUnity NoelStephensUnity added the port:1.x-needed This issue needs to be ported to 1.X branch label Jul 11, 2025
@NoelStephensUnity NoelStephensUnity marked this pull request as draft July 11, 2025 17:45
NoelStephensUnity added a commit that referenced this pull request Aug 14, 2025
applying the fixes from #3527 where applicable.
@NoelStephensUnity NoelStephensUnity marked this pull request as ready for review August 14, 2025 22:44
@NoelStephensUnity NoelStephensUnity added port:1.x-completed This issue was ported to 1.X branch and removed port:1.x-needed This issue needs to be ported to 1.X branch labels Aug 14, 2025
adding changelog entry.
@NoelStephensUnity NoelStephensUnity enabled auto-merge (squash) August 14, 2025 22:51
Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samlucas-unity Looks good and thank you for the fix! Sorry for the delay on getting this back ported.

@NoelStephensUnity NoelStephensUnity merged commit 3dcc65a into develop-2.0.0 Aug 15, 2025
25 checks passed
@NoelStephensUnity NoelStephensUnity deleted the fix/avoid-unnecessry-gc-alloc branch August 15, 2025 02:44
NoelStephensUnity added a commit that referenced this pull request Aug 15, 2025
Fix for [MTTB-85](https://jira.unity3d.com/browse/MTTB-85) removed the
use of a foreach causing an unnecessary GC Allocation.

Did a full sweep of internal `NetworkManager.ConnectedClientsIds` and
replaced with either `for` loop or directly referencing the
`NetworkConnectionManager.ConnectedClientIds`.

## Changelog

- Fixed: Issue with unnecessary internal GC Allocations when using the
`IReadOnlyList` `NetworkManager.ConnectedClientsIds` within a `foreach`
statement by either replacing with a `for` loop or directly referencing
the `NetworkConnectionManager.ConnectedClientIds`.

## Documentation

- No documentation updates were required.

## Testing & QA
[//]: #  (
This section is REQUIRED and should describe how the changes were tested
and how should they be tested when Playtesting for the release.
It can range from "edge case covered by unit tests" to "manual testing
required and new sample was added".
Expectation is that PR creator does some manual testing and provides a
summary of it here.)

### Functional Testing
[//]: # (If checked, List manual tests that have been performed.)
_Manual testing :_
- [X] `Manual testing done`
- Tested manually before and after fix to confirm the allocation was
present and then absent.

_Automated tests:_
- [ ] `Covered by existing automated tests`
- [ ] `Covered by new automated tests`

_Does the change require QA team to:_

- [ ] `Review automated tests`?
- [ ] `Execute manual tests`?

If any boxes above are checked, please add QA as a PR reviewer.


## Backport
This is the backport for #3527
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

port:1.x-completed This issue was ported to 1.X branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants