perf(feeds): frame-budget governor for camera feeds#22
Merged
Conversation
Build on the round-robin feed scheduler (one camera render+readback per tick) with an adaptive frame-budget governor. The heavy part of a feed tick — a full scene render to the camera's target plus a synchronous pixel readback — is timed into an EMA; when that cost exceeds FEED_FRAME_BUDGET_MS the heavy path runs only every Nth tick (stride grows with cost, capped at MAX_FEED_STRIDE=6), so feeds back off and yield the main thread/GPU to the render loop under load. Cheap per-tick patrol updates still run every tick, so camera motion stays smooth; at low load stride stays 1 (unchanged cadence). When feeds are hidden the render-to-target cost is still folded into the EMA so the governor keeps adapting for the detection path. Worst case at MAX_FEED_STRIDE still refreshes ~every 0.5 s. Closes the lag-fix arc started by the round-robin + splat perf-mode work. typecheck + lint clean; 230 unit tests pass.
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.
What
Builds on the round-robin camera-feed scheduler (one camera render + pixel readback per tick) with an adaptive frame-budget governor.
The heavy part of a feed tick is a full scene render to the camera's render target plus a synchronous
readRenderTargetPixelsreadback — the op that stalls the main render loop, worst with multi-million-splat scenes. The governor:feedCostEmaRef);stride = clamp(round(cost / FEED_FRAME_BUDGET_MS), 1, MAX_FEED_STRIDE);strideticks, so feeds back off and yield the main thread/GPU under load.Properties
stride === 1(every tick), identical to current behavior.MAX_FEED_STRIDE = 6and the 83 ms interval, a feed still refreshes ~every 0.5 s.Why
Completes the lag-fix arc (splat performance mode → round-robin feeds → frame-budget governor): the feed subsystem now spends only a bounded slice per tick and gives time back to the render loop precisely when the scene is heavy.
Verification
bun run typecheck— cleaneslint— clean (only the pre-existingmax-lineswarning on this file)bun run test:run— 230 passed, 8 skippedGuarded going forward by
scripts/perf-smoke.mjs(splatWithFeedsFPS floor).