Repository navigation
Fix latency performance - #232
Merged
Merged
Conversation
sendToAllSync previously created a new asyncio task (via run_coroutine_threadsafe) for every message. The runtime publishes metrics, results and camera frames continuously, so that meant thousands of task allocations per second on the websocket loop. Messages are now handed to a single long-lived send task that drains a queue, which also guarantees ordering and applies natural backpressure. createMessage reuses a module-level field-name set instead of rebuilding it per message.
publishFrame always called cv2.resize, even when the captured frame already matched the requested stream/recording size, and allocated a fresh destination image for every published frame. Skip the resize when dimensions already match and reuse a per-camera destination buffer when they do not. The recording buffer is released when a recording stops.
- Cache each camera's view id behind an NT listener instead of calling entry.exists()/getString() on every frame; only the listener touches NetworkTables now. - Publish Apriltag hasResults and tag_id only when their value changes instead of re-sending them (and serializing to NT + the UI) every frame. - In parsePipelineResult, resolve geometry through the module-level import and check containers before the geometry chain, since lists/dicts are the common result shape.
- Load fmap.json once and share it between pipeline instances instead of parsing the JSON for every ApriltagPipeline created. - Cache the computed crop rectangle and only recompute it when the image size or crop settings change. - Convert to grayscale into a reusable buffer rather than allocating a new image per frame; the OpenCV output is contiguous, so the extra ascontiguousarray copy is no longer needed. - Draw the tag outline with a single cv2.polylines call and compute the center without a temporary numpy array.
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.
improves around 2ms of latency per frame