Skip to content

Remove three more admission-path allocation sites and re-derive the ESP stacks - #229

Merged
kahrendt merged 5 commits into
alloc-4-handshake-statefrom
alloc-5-admission-tail
Nov 3, 2026
Merged

kahrendt merged 5 commits into
alloc-4-handshake-statefrom
alloc-5-admission-tail

Conversation

@kahrendt

@kahrendt kahrendt commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Layer 5 of 7 (base: alloc-4-handshake-state). Accept to admission: 11 -> 6 allocations under libc++, 13 -> 8 under libstdc++; one client/state publish: 3 -> 0.

Summary

Three more admission-path allocation sites go: the last-played server id, the pairing notes and the player's client/state object. This layer also re-derives the ESP task stacks for layers 2 to 5.

Changes

  • The last-played server_id is an IdText in the manager and in the persist request, and admission takes it as a view, empty meaning none. note_last_played_server() and write_last_played_server() take a string_view; they are private members, and client.h gains <string_view>. RecordStore::take_dirty_writes_locked() returns before reserving when no record write is owed, which is every flush a playback handoff stages for the last-played server alone.
  • push_pairing_note() appends through InboxSlot::update() instead of merging a one-element vector.
  • ClientPlayerStateObject::supported_commands is an EnumSet, a one-byte bit set that ActivitySet now shares. client/state lists the commands in enumerator order, which is the order the player added them in, so the wire output is unchanged.
  • tools/stack_usage/README.md: the protocol task's reachable chain is 5,920 / 6,400 B (-Os / -Og), so its 7,168 default stands; the websocket client's -Og total moves to 3,968, inside its 4,608 default. No default changes.

Testing

  • The supported-commands test now uses a set with a gap, built out of order, so an iteration that stops early or follows insertion order fails it.

Still allocating, on purpose: copies of the public ServerInformationObject, and the pairing-note slot's vector on its first note after each drain.

@kahrendt kahrendt changed the title Remove the remaining admission-path allocations and re-derive the ESP stacks Remove three more admission-path allocation sites and re-derive the ESP stacks Nov 3, 2026
@kahrendt
kahrendt added this pull request to stack #232 November 3, 2026 14:10
@kahrendt
kahrendt force-pushed the alloc-5-admission-tail branch from 401cf8f to 1e5a165 Compare November 3, 2026 14:38
ConnectionManager keeps the last-played server_id, and the persist request
carries it, as an IdText rather than a heap string; admission takes it as
a view, empty meaning none. RecordStore::persist_records() returns before
reserving when no record write is owed, which is every flush a playback
handoff stages for the last-played server alone.

Accept to admission: 11 -> 8 allocations under libc++, 13 -> 10 under
libstdc++.
push_pairing_note() appends through InboxSlot::update() instead of
merging a one-element vector, so a pairing or trust note no longer
allocates a delta.

Accept to admission: 8 -> 7 allocations under libc++, 10 -> 9 under
libstdc++.
ClientPlayerStateObject::supported_commands becomes an EnumSet, a
one-byte bit set that ActivitySet now shares, so building, copying and
filtering a client/state no longer allocates. client/state lists the
commands in enumerator order, the order the player added them in.

Accept to admission: 7 -> 6 allocations under libc++, 9 -> 8 under
libstdc++; one client/state publish: 3 -> 0.
Re-run tools/stack_usage over the branch at -Os and -Og. The protocol
task's reachable chain is 5,920 / 6,400 bytes, so its 7,168 default
stands; the websocket client's -Og total moves to 3,968, inside its
4,608 default. No default changes.
ClientPlayerStateObject is trivially copyable now that its supported
commands are a set, so std::move() into the message did nothing
(performance-move-const-arg).

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.

🟢 Approval recommended

No active review issues remain for the allocation-reduction changes and related ESP stack measurement updates.

No open issues 🎉

What changed in this PR

This PR continues the library’s allocation-reduction work by removing three admission-path allocation sites and refreshing ESP stack measurements without changing stack defaults.

Changes:

  • Uses fixed-capacity storage for last-played server IDs and player commands, appends pairing notes directly, and skips unnecessary persistence allocation.
  • Updates allocation expectations to 6/8 for admission and zero for player client/state, with coverage for sparse command sets and enumerator ordering.
  • Updates measured ESP stack usage, which remains within existing defaults.
File Description
tools/​stack_usage/​README.md Refreshes ESP stack measurements and sizing calculations.
tests/​test_protocol.cpp Checks sparse, out-of-order command-set serialization.
tests/​test_player_role.cpp Uses command sets in expected player state.
tests/​test_allocations.cpp Lowers admission and state-publication allocation expectations.
tests/​test_admission.cpp Adapts last-playback cases to empty-string semantics.
src/​record_store.cpp Skips allocation when no record writes are pending.
src/​protocol.cpp Serializes supported commands in enumerator order.
src/​protocol_messages.h Introduces a shared one-byte enum set for activities and commands.
src/​player_role.cpp Builds supported commands without vector allocation.
src/​connection_manager.h Stores the last-played ID inline and exposes a view.
src/​connection_manager.cpp Uses the stored ID view for admission decisions.
src/​client.cpp Removes temporary pairing-note and last-played-ID allocations.
src/​admission.h Accepts the last-playback ID as a string view.
include/​sendspin/​client.h Updates private persistence helpers to accept string views.

Review effort: Balanced

@kahrendt
kahrendt merged commit be7fdf5 into main Nov 3, 2026
17 of 33 checks passed
@kahrendt
kahrendt deleted the alloc-5-admission-tail branch November 3, 2026 16:01
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