Fix frame pacing once and for all#135
Merged
Merged
Conversation
Temporal-compression batching used to surface as frames spooled at regular intervals, but timing predicted from the server's reported gen_ms doesn't account for wire-side jitter or per-batch overhead — small drifts between predicted and actual cadence translated directly into visible timing variance. Server now bundles all T sub-frames of an inference pass into one binary WS message (PROTOCOL_VERSION bumped to 4). Client maintains an EMA of inter-batch arrival intervals and schedules each sub-frame's display at receivedAt + (arrivalEMA / T) * i, so they spread evenly across the predicted next-batch interval. Drop-on-overlap and hold-on-underrun cover the EMA-misprediction edges; both surface as HUD metrics for tuning.
A multi-second pause/resume or scene-edit interval would surface to the pacer as a single batch arrival with `arrivalInterval = pause_duration`. At α=0.2 the EMA blended 20% of that gap into the prediction, blowing `step_s` up to hundreds of ms per sub-frame for ~20 recovery batches (~1.5s at typical cadence) before decaying back — visible as a noticeable slowdown for the first few seconds after every resume. Treat any gap > 500ms (absolute) or > 5× current EMA (relative) as a discontinuity and snap the EMA to `header.gen_ms` instead of blending. Same branch also skips overlap/hold accounting for the stale outgoing batch, since those metrics only mean anything when we expected continuous flow.
Clydingus
reviewed
May 13, 2026
Clydingus
approved these changes
May 13, 2026
Added in the initial pacing redesign as "lets the client distinguish server-side timing from network jitter," but the pacer ended up using performance.now() at receive exclusively — nothing reads the field.
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.
Fixes #113. Makes the frame pacing algorithm more intelligent (i.e. targeting an EMA of time between received batches) to improve smoothness of presentation and to cope with being capped better.