Skip to content

Share the fixed-size vocabulary across its sibling sites - #245

Merged
kahrendt merged 2 commits into
mainfrom
bounded-vocabulary
Nov 4, 2026
Merged

kahrendt merged 2 commits into
mainfrom
bounded-vocabulary

Conversation

@kahrendt

@kahrendt kahrendt commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Summary

From the second coherence pass on the allocation follow-ups (Sendspin/backlog#92): sibling sites that hold the same bounded values in different shapes. The Noise handshake encoded its fixed 50-byte msg2 into a fallible heap buffer while the pairing fields use a stack encoder; server/hello's source codecs were a hand-rolled bit mask beside EnumSet; the open-connection psk-id list was the last bounded id list held as std::vector<std::string>; and a few role members disagreed with their neighbors.

Change

  • base64url: b64url_encode_to() (protocol.cpp's write_b64url, still wiping its stack buffer) joins b64url_decode_exact() in platform/base64.h. build_noise_handshake_message() encodes msg2 with it and returns void, so the handshake and re-handshake lose their allocation-failure branches.
  • EnumSet: moves to src/enum_set.h with its own test. server/hello's source_codecs is an EnumSet<SendspinCodecFormat>; source_codec_bit() is gone. The uint16 role masks stay, and internals.md "Memory" says why the two role-set shapes differ.
  • psk-id list: open_connection_psk_ids() returns an InlineVector of pointers to the connections' psk ids, valid for the protocol-task step that asked; store_record_superseding() and the eviction helper take a span of them. Pointers rather than IdText copies keep a ~184-byte temporary off process_json_message()'s frame, which every JSON message shares. The store's own id copies are gone.
  • Small shapes: the artwork role's configured artwork_channels is an InlineVector like streamed_channels; hand_flac_header() takes a string_view; the FLAC decoder's creation notes that micro-flac allocates internally, so it is not a PlatformBuffer like the Opus state.
  • Stack: the protocol task's -Og bound goes 6,688 -> 6,704 and its reachable pairing-confirm chain 6,144 -> 6,160 (the pointer list). The README's -Os figure moves 6,544 -> 6,560, already the measured value before this change. The 7,168 default is unchanged; no other task moved.

Tests

  • EnumSet.VisitsEachMemberOnceInEnumeratorOrder: insertion order, repeats, the eighth enumerator and empty; a short for_each bound and an assigning insert fail it.
  • Protocol.ServerHelloSourceSupportListsAcceptedCodecs runs on the set; dropping the FLAC requirement fails it.
  • RecordStore.EvictionSkipsRecordsBackingOpenConnections and NothingEvictableRejectsTheRecord take the pointer span; removing the in-use skip fails both.

- b64url_encode_to() (was protocol.cpp's write_b64url) joins
  b64url_decode_exact() in platform/base64.h; the handshake encodes its
  50-byte msg2 with it, so build_noise_handshake_message() no longer
  allocates or fails and both callers lose their error branch.
- EnumSet moves to its own header with a test, and server/hello's source
  codecs are an EnumSet<SendspinCodecFormat> instead of a hand-rolled
  mask.
- open_connection_psk_ids() returns an InlineVector of pointers to the
  connections' psk ids, kept off the JSON dispatch frame, and the record
  store takes a span of them; the store's id copies are gone.
- The artwork role's configured channels are an InlineVector like its
  streamed ones, hand_flac_header() takes a string_view, and the FLAC
  decoder's creation says why it is not a PlatformBuffer.
- Protocol task stack figures re-derived (default unchanged at 7,168).
@kahrendt
kahrendt marked this pull request as ready for review November 4, 2026 19:13
@kahrendt
kahrendt requested a max review from Copilot November 4, 2026 19:13

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

Inserting B2 three times lets an incorrect ^= implementation pass all current test cases, leaving duplicate-insertion behavior insufficiently tested.

1 open issue
What changed in this PR

Consolidates bounded protocol values around shared helpers and inline containers, reducing temporary heap allocation and keeping sibling implementations consistent in sendspin-cpp.

Changes:

  • Shares the stack-based base64url encoder across pairing and Noise handshake messages.
  • Extracts EnumSet and uses bounded containers for source codecs, open-connection PSK IDs, and artwork channels.
  • Updates tests, allocation documentation, and protocol-task stack figures without changing the stack default.
File Description
tools/​stack_usage/​README.md Updates protocol-task stack bounds and margin calculations.
tests/​test_record_store.cpp Adapts eviction tests to PSK-ID pointer spans.
tests/​test_protocol.cpp Uses EnumSet in source-codec parsing expectations.
tests/​test_enum_set.cpp Adds membership, ordering, and duplicate-insertion coverage.
tests/​CMakeLists.txt Registers the new EnumSet test file.
src/​record_store.h Changes in-use PSK-ID parameters to pointer spans.
src/​record_store.cpp Consumes pointer spans and removes temporary ID copies.
src/​protocol.cpp Reuses the base64url helper and source-codec set.
src/​protocol_messages.h Imports EnumSet and applies it to source-codec support.
src/​player_role.cpp Accepts FLAC headers through string_view.
src/​player_role_impl.h Updates the FLAC-header helper declaration.
src/​platform/​secure_zero.h Documents base64 helpers as another buffer-wiping caller.
src/​platform/​base64.h Adds the shared stack encoder with scratch-buffer wiping.
src/​noise_handshake.h Narrows the envelope builder to fixed-size msg2 input.
src/​noise_handshake.cpp Removes encoding scratch allocation and its failure branch.
src/​enum_set.h Extracts the reusable one-byte enum set.
src/​decoder.cpp Adds a comment explaining micro-flac’s internal allocations.
src/​connection.h Stores and queries source codecs through EnumSet.
src/​connection.cpp Adapts re-handshaking to the void envelope builder.
src/​connection_manager.h Declares bounded PSK-ID pointers and their lifetime.
src/​connection_manager.cpp Collects connection-owned PSK-ID pointers without copying strings.
src/​artwork_role_impl.h Stores configured artwork channels in an InlineVector.
docs/​internals.md Updates allocation details and explains role-set representations.
CLAUDE.md Documents the standalone secure-erasure header.

Review effort: Max

Comment thread tests/test_enum_set.cpp Resolved
An odd count let an insert that toggles its bit produce the expected
set.
@kahrendt
kahrendt merged commit 2739632 into main Nov 4, 2026
16 checks passed
@kahrendt
kahrendt deleted the bounded-vocabulary branch November 4, 2026 19:41
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