Skip to content

Avoid rebuilding peer UI on every status snapshot - #136

Open
tyrspawn wants to merge 4 commits into
developfrom
codex/peer-list-memory
Open

tyrspawn wants to merge 4 commits into
developfrom
codex/peer-list-memory

Conversation

@tyrspawn

@tyrspawn tyrspawn commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Summary

Keep frequency group and peer row view models stable across full peer-status snapshots. The client now reconciles rows by frequency and peer ID, updating fields in place and inserting, moving, or removing only changed items. This avoids rebuilding the Avalonia peer panel for every server snapshot.

Incident context

This memory issue was observed during UOAF Event 750. I was flying as Bulldog21 when the client froze, followed by CFIT. I rejoined as Bulldog24. During the final attack on SA-17 East, I experienced a disconnect/desync and was shot down by a Su-27. Shared investigation and discussion.

Dump analysis

A full dump from OpenFreq Client 1.1.5 after roughly two hours of use showed:

Managed object Present in heap Reachable at capture
ChannelPeerViewModel 88,590 92
ChannelFrequencyPeerViewModel 14,206 18
Avalonia.Controls.Shapes.Ellipse 177,198 196
All managed objects 49,879,900 / 4,623 MB 389,458 / 79 MB

The peer row XAML creates two ellipses per row. 2 × 88,590 = 177,180, accounting for nearly every ellipse in the dump. The old RebuildPeerLists implementation created new view models, cleared both bound collections, and added every group on each full snapshot. Avalonia consequently recreated the corresponding controls and bindings. Most of that memory was collectible at capture, but it remained in the committed Gen2 heap. A separate 2 GiB read-only heightmap mapping was also present in the dump; it is not the 4.6 GB managed heap.

The dump was captured shortly after BMS exited, so the 79 MB reachable figure describes that moment. It does not establish peak liveness during gameplay. The dump itself is not uploaded because it contains user/session data.

Changes

  • Reconcile existing frequency groups and peer rows instead of clearing and rebuilding their collections.
  • Update name, transmission state, own-user styling, and join availability on retained view models.
  • Notify derived peer counts when membership within a retained group changes.
  • Add regression tests for repeated identical snapshots, targeted membership/property changes, and BMS/GCI join eligibility.
  • Refresh join availability on connection mode changes so switching from GCI to BMS hides join controls immediately.
  • Add three missing XML summary tags in existing code so the repository lint gate can run.

Verification

  • dotnet test OpenFreq.sln -c Release --nologo: 442 passed (129 client, 153 common, 160 server).
  • dotnet build OpenFreq.Client.Tests/OpenFreq.Client.Tests.csproj -c Release --no-restore -warnaserror: 0 warnings, 0 errors.
  • Targeted dotnet format --verify-no-changes for changed files: passed.

@github-actions

Copy link
Copy Markdown
Contributor

Code Coverage

Package Line Rate Branch Rate Health
OpenFreq.Common 79% 72% ➖
OpenFreq.Client 30% 22% ❌
OpenFreq.Server 86% 83% ✔
Summary 45% (2946 / 6509) 35% (742 / 2126) ❌

@mrkline

mrkline commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

This seems like a good idea, instead of rebuilding the peer list from whole cloth on each update, though:

  1. We should remove stale items before shifting the remaining ones around - see 7de5c1b
  2. "Over 4 GB of garbage was unreachable but hadn't been GC'd" doesn't pass the sniff test (I assume the .NET GC isn't that bad at its job) unless something kept that memory resident until right before taking the dump. (Maybe until you exited BMS?) If folks see memory usage growing as they play the game, that'd be helpful to grab a dump of.

@richionizor

Copy link
Copy Markdown
Contributor

Food for thought: there are two different issues we should look into (and decide what we want to solve):

  • Memory leaks due to recreation of items and holding references which inhibit the ObservableCollection to clean up properly - we have to see if there is a repro case for that
  • CPU usage due to recreating all of the controls on the fly - https://docs.avaloniaui.net/docs/app-development/performance is a good ressource on this, the TLDR would be to check if we use virtualized UI containers for the lists to ensure that we just create the controls that are currently rendered

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.

3 participants