Repository navigation
View client/state's artwork channels and visualizer types - #240
Merged
Merged
Conversation
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.
Contributor
There was a problem hiding this comment.
🟡 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
- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
Group D of the allocation follow-ups (Sendspin/backlog#92).
client/statecopied the artwork channels and visualizer types intostd::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 fromadd_*(), so the state objects now view them.Change
ClientArtworkStateObject::channelsandClientVisualizerStateObject::typesarestd::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.ClientStateMessageis now trivially copyable, and astatic_assertwith 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()andstop()copy or reset under the lock instead of swapping a heap-backed snapshot out, and the moves of the snapshot are gone.conventions.mdallows a view (std::span,std::string_view) of configuration fixed fromadd_*();internals.md"Memory" drops theclient/staterow.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 perclient/state; now 0.client/stateit measured and checks both artwork channels and the visualizer type; a mutant that drops the artwork object fails it in both windows.