fix: conflation to avoid latency buildup #21
Merged
+22
−11
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.
Proposed Changes
AsyncStreamwith a buffer policy of.bufferingNewest(1).Why this is needed
I was running into an issue where latency would start low but get progressively higher the longer the stream ran.
It turns out the previous loop was forcing frames at 200Hz, but the network connection couldn't always keep up. Since
response.writeaccepts data faster than it actually transmits, we were building up a huge internal queue of old frames. The client was receiving every single packet, but by the time they arrived, they were stale (which would lead to a large buildup of latency).This fix implements conflation (dropping old frames). We now have a buffer of exactly one frame (can also be increased, this way we keep latency low). If the network is busy sending the previous packet, the generator simply overwrites the buffer with the absolute latest hand pose. This prevents the backlog from building up and keeps latency constant.