piker icon indicating copy to clipboard operation
piker copied to clipboard

Graphics update throttling

Open goodboy opened this issue 4 years ago • 1 comments
trafficstars

This became a requirement after deploying binance feeds which hit trade / book quote rates in the 500-1k Hz instantaneous rate range (with high burstiness obvs) pretty often. The original patch is in #177.

Premises:

  • there's no point in updating graphics faster then the local display rate
  • the max update rate should be also limited by measured latency in python "draw cycles" (i.e. the min wait period should be the max refresh refresh period plus additionally measured processing time from python code in update loops)
  • taking a naive approach (no fancy v-sync type stuff yet) will at most update graphics once per physical display cycle even if the synchronization with hardware is off
  • limiting to refresh rate should mitigate most forms of tearing presuming we keep updates below the display rate
  • there might be a way to actually hook into Qt draw cycle events using QPaintEngine.updateState which would maybe allow us to check for state that would suggest that a draw cycle is imminent?

TODOs for the interested graphics-onistas

  • [ ] allow specifying the throttle rate in a piker.toml
  • [ ] consider a less naive approach then our current hard coded rounding to the QScreen.refreshRate()
  • [ ] offer the throttle api through a composable generator?
    • maybe something like:
          async def throttle_to(async_iter: AsyncIterable[T], rate:int = 60) -> T:
      
              last = time.time()
              processing_total = 0.001  # heuristic default
      
              async for val in async_iter:
                  if time.time() - last <= 1/rate - processing_total:
                      continue
                  else:
                      processing_start = time.time()
                      yield val
                      processing_total = time.time() - processing_start
                      last = time.time()
      

Some further resources from #177 re: v-sync (though not sure if we should dig this deep yet):

goodboy avatar May 25 '21 12:05 goodboy

not sure why #192 isn't linked here, but it should be.

goodboy avatar Sep 28 '21 12:09 goodboy