Repository navigation
Publish each admitted slot's clock instead of sharing its filter - #231
Merged
Merged
Conversation
7 tasks done
kahrendt
force-pushed
the
alloc-7-clock-slots
branch
from
November 3, 2026 14:38
5cf9b67 to
0b4f933
Compare
A connection's SendspinTimeFilter becomes a by-value member used on the protocol task only, so it loses its mutex and its shared_ptr. Role threads read a TimeTransform instead: the filter's offset and drift as of its latest measurement, which refresh_published_state() copies into one slot per admitted connection whenever a measurement, a slot's connection or the primary moved it. ConnectionManager::clock() returns the primary's, which is_time_synced() and get_client_time() convert through as before. A reader shares nothing with the connection, and a second admitted connection gets its own clock slot. Accept to admission: 4 -> 3 allocations under libc++, 6 -> 5 under libstdc++.
kahrendt
force-pushed
the
alloc-7-clock-slots
branch
from
November 3, 2026 15:15
0b4f933 to
84b228a
Compare
kahrendt
marked this pull request as ready for review
November 3, 2026 15:36
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The lifecycle test covers only the newcomer’s first measurement, leaving subsequent clock corrections and snapshot visibility before and after publication untested.
1 open issue
What changed in this PR
This PR replaces shared, mutex-protected time filters with connection-owned filters and published clock snapshots, removing one allocation per admitted connection.
Changes:
- Keeps live filters on the protocol task and publishes per-slot clock transforms for other threads.
- Updates clock consumers, lifecycle coverage, and allocation expectations.
- Revises architecture and synchronization documentation.
| File | Description |
|---|---|
| tests/test_source_role.cpp | Uses connection-owned filters in source tests. |
| tests/test_noise_transport.cpp | Removes explicit filter initialization. |
| tests/test_client_lifecycle.cpp | Checks publication of a post-admission measurement. |
| tests/test_allocations.cpp | Lowers expected admission allocations by one. |
| src/time_filter.h | Defines TimeTransform and removes the filter mutex. |
| src/time_filter.cpp | Moves conversions into the snapshot type. |
| src/time_burst.h | Updates the filter-access documentation example. |
| src/time_burst.cpp | Updates connection-owned filters directly. |
| src/source_role.cpp | Timestamps outgoing chunks through the live filter. |
| src/connection.h | Stores the filter directly in each connection. |
| src/connection.cpp | Removes heap-based filter initialization. |
| src/connection_manager.h | Declares published clock slots and the snapshot getter. |
| src/connection_manager.cpp | Publishes changed transforms and primary-slot state. |
| src/client.cpp | Reads published snapshots for public clock queries. |
| docs/playback-sync.md | Explains snapshot-based timestamp conversion. |
| docs/internals.md | Updates publication, threading, and lock documentation. |
| docs/conventions.md | Revises shared-state and lock conventions. |
| CLAUDE.md | Updates the connection manager’s architecture description. |
Review effort: Balanced
The lifecycle test covered only the newcomer's first measurement, which flips synced, so a publish that fired only on that flip or on a primary change would have frozen readers at the first burst's clock unnoticed. A second measurement now has to move get_client_time() to its offset.
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.

Layer 7 of 7 (base:
alloc-6-per-connection). Accept to admission: 4 -> 3 allocations under libc++, 6 -> 5 under libstdc++.Summary
Each connection's time filter was a
shared_ptrwith its own mutex, published so role threads could convert timestamps without holding the connection. The filter is now a plain member used on the protocol task only, and other threads read a copy of its conversion. This is the one layer that changes a threading arrangement, so it sits on top.Changes
TimeTransform(time_filter.h): the filter's offset, the drift it applies and its last update, with both conversions. The filter's own conversions run on it, unchanged bit for bit, andSendspinTimeFilterlosesstate_mutex_.refresh_published_state()(tick step 11) publishes oneTimeTransformper admitted slot, plus the primary's slot, and takespublished_mutex_only when a measurement, a slot's connection or the primary changed one.ConnectionManager::clock()replacestime_filter()and returns the primary's.is_time_synced()andget_client_time()readclock(), so they report the filter as of the end of the protocol tick that last changed it, not the live filter. The client/state clock gate and the source role read the live filter on the protocol task.MAX_ADMITTEDis 1, so there is one slot today; publishing per slot leaves room for a second admitted connection, such as an announcement-only server, to have its own clock.docs/internals.md,conventions.md,playback-sync.mdandCLAUDE.mddescribe the published clocks; the lock list loses the filter's mutex.Testing
The whole stack ran on an ESP32 with no issues.