Skip to content

Conversation

NoelStephensUnity
Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity commented Aug 14, 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

This is the backport for #3527

applying the fixes from #3527 where applicable.
Adding changelog entry.
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
The backport of this PR is #3601

---------

Co-authored-by: NoelStephensUnity <[email protected]>
@NoelStephensUnity NoelStephensUnity merged commit 1edc2ab into develop Aug 15, 2025
27 checks passed
@NoelStephensUnity NoelStephensUnity deleted the fix/avoid-unnecessry-gc-alloc-backport branch August 15, 2025 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants