Skip to content

View client/state's artwork channels and visualizer types - #240

Merged
kahrendt merged 2 commits into
mainfrom
client-state-inline
Nov 4, 2026
Merged

kahrendt merged 2 commits into
mainfrom
client-state-inline

Conversation

@kahrendt

@kahrendt kahrendt commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Group D of the allocation follow-ups (Sendspin/backlog#92). client/state copied the artwork channels and visualizer types into std::vectors on the main loop, then again for each connection on the protocol task, and the allocation test could not see it because its client had neither role. Both values are role configuration fixed from add_*(), so the state objects now view them.

Change

  • Role objects: ClientArtworkStateObject::channels and ClientVisualizerStateObject::types are std::spans of the artwork role's channel list and the visualizer role's configured types. The wire output is unchanged. The two viewed fields say so at their declarations.
  • Snapshot: ClientStateMessage is now trivially copyable, and a static_assert with a comment says why its views stay valid across ticks (a role is replaced only while the client is stopped, and the protocol task reads only a snapshot its run published). ProtocolTask::publish_state(), take_state() and stop() copy or reset under the lock instead of swapping a heap-backed snapshot out, and the moves of the snapshot are gone.
  • Docs: conventions.md allows a view (std::span, std::string_view) of configuration fixed from add_*(); internals.md "Memory" drops the client/state row.

Tests

  • sendspin_alloc_tests' client adds two artwork channels and a visualizer. With the old vectors it counts 2 library allocations at admission and 4 per client/state; now 0.
  • After each window closes, the test parses the client/state it measured and checks both artwork channels and the visualizer type; a mutant that drops the artwork object fails it in both windows.

client/state copied the artwork channels and visualizer types into
std::vectors on the main loop and again for each connection on the
protocol task. Both are role configuration fixed from add_*(), so the
role objects now hold std::spans of them, and ClientStateMessage is
trivially copyable (a static_assert says so).

- The snapshot slot copies under the lock instead of swapping a
  heap-backed snapshot out, and the moves of the snapshot are gone.
- The allocation test's client adds two artwork channels and a
  visualizer; with the old vectors it counts 2 allocations at admission
  and 4 per client/state.
- conventions.md allows a view of configuration fixed from add_*();
  internals.md "Memory" drops the client/state row.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Cross-run view lifetimes lack lifecycle tests covering role replacement and restart, leaving stale snapshots or use-after-free risks untested.

5 open issues
What changed in this PR

This PR removes heap-backed artwork and visualizer configuration copies from client/state, reducing allocations on the main loop and protocol task while preserving the wire format.

Changes:

  • Replace channel and type vectors with spans over fixed role configuration.
  • Make state snapshots trivially copyable and simplify locked publication, consumption, and clearing.
  • Expand allocation coverage, adapt existing tests, and document the view lifetimes.
File Description
tests/​test_visualizer_role.cpp Compare reported span contents with expected types.
tests/​test_protocol.cpp Use array-backed spans in serializer fixtures.
tests/​test_allocations.cpp Add artwork and visualizer roles to allocation measurements.
src/​visualizer_role.cpp Copy the span-based visualizer state object.
src/​visualizer_role_impl.h Document configuration storage viewed by snapshots.
src/​protocol_task.h Update snapshot publication signature and slot documentation.
src/​protocol_task.cpp Copy and reset snapshots under the slot lock.
src/​protocol_messages.h Introduce spans and assert trivial snapshot copying.
src/​client.cpp Adopt state snapshots by copying.
src/​client_dispatch.cpp Pass consumed snapshots without moving.
src/​artwork_role.cpp Copy the span-based artwork state object.
src/​artwork_role_impl.h Document fixed channel storage viewed by snapshots.
include/​sendspin/​client.h Update the private snapshot-adoption signature.
docs/​internals.md Describe configuration views and remove their allocation entry.
docs/​conventions.md Allow views of configuration fixed at role registration.

Review effort: Max

Comment thread src/protocol_messages.h Resolved
Comment thread include/sendspin/client.h Resolved
Comment thread src/protocol_messages.h Resolved
Comment thread tests/test_allocations.cpp Resolved
Comment thread tests/test_visualizer_role.cpp Resolved
- The allocation test parses each measured client/state after its
  window closes and checks the two artwork channels and the
  visualizer's type, so a missing role object cannot pass as 0.
- Role registration is stated as the caller's precondition (client.h
  "Role registration"), which add_*() does not enforce.
- test_player_role.cpp drops a move into the const& parameter;
  test_visualizer_role.cpp compares vectors so a failure prints both.
@kahrendt
kahrendt merged commit c5eb9c5 into main Nov 4, 2026
16 checks passed
@kahrendt
kahrendt deleted the client-state-inline branch November 4, 2026 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants