Skip to content

Bound WebSocket receive buffering and remove spin wait - #1

Draft
Lyptik wants to merge 1 commit into
mainfrom
perf/bounded-websocket-message-buffer
Draft

Lyptik wants to merge 1 commit into
mainfrom
perf/bounded-websocket-message-buffer

Conversation

@Lyptik

@Lyptik Lyptik commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Why

The Unity client currently appends WebSocket messages to an unbounded List<MessageEventArgs> and uses a busy while (isProcessing) { } loop around the handoff. If the Unity main thread falls behind high-rate or point-cloud traffic, the list can grow with consumer lag and retain increasingly large binary payloads.

Changes

  • replace the unbounded list with a small bounded FIFO (3 messages)
  • use a lock/condition handoff instead of the spin wait
  • apply natural backpressure in the WebSocket callback when Unity is behind
  • preserve message ordering and transient Augmenta events; no raw-frame dropping
  • process only the batch pending at the start of each Unity Update()
  • wake blocked producers on disconnect/disable and clear stale queued messages
  • ignore callbacks from sockets that have already been replaced

Why FIFO/backpressure here

Unlike a pure renderer, Unity's current client feeds the stateful C# Augmenta client. Dropping raw binary messages before parsing could lose cluster/zone transitions. A tiny bounded FIFO therefore gives us bounded application memory without changing protocol/event semantics.

Unchanged

  • usePolling = false
  • useCompression = true
  • protocol options and public Unity API

@Lyptik Lyptik self-assigned this Oct 15, 2026
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.

1 participant