Hi Chris,
Answering in-line, excuse the bad formatting, this e-mail client has
failed and I've done my best...
=) I'm afraid the modern world of forums does crazy things to E-mail for some reasons - particularly indented blocks which I rather like, let me try to train myself out of that.
The flow of events ought to be along the lines of:
- Server: Change triggers redrawing of an area
- Server: Invalidation rectangles are sent to client
- *Client: Received invalidation rectangles and marks related tiles
as invalid
- *Client: Sends tile request for newly invalid area
- *Server: Receives tile request
- Server: Sends related tiles
Ok - so the '*' pieces will get short-circuited on the server side for all sensible cases to avoid latency; so you can assume you get:
- Server: Invalidation rectangles are sent to client
- short delay depending on invalidated size -
- Server: Sends related tiles
With no need for another round-trip - so the '*'d bits are already not there.
- Client: Receives tiles, possibly over some length of time -
drawing is paused while we wait for visible, requested tiles
Great.
The code that deals with this is scattered about in
TilesMiddleware.ts, check out `pausedForCoherency` and
`deferDrawing`. I don't think it currently handles invalidations
entirely as we/I expect and we need to think about timeouts too
Fair cop. So - I'm well up for doing the delaying at a different level - clearly the delaying is not very polished where it is anyway - it is buggy in that it doesn't adapt to the count of already received tiles which is poor, it probably adds extra latency we don't need as well.
Yes, preaching to the choir here
I count 'flickering' as a subset of 'visual incoherency' - we should never be displaying partially rendered frames, in-between frames, etc.
Great - as long as we're on the same page that's fine =) I know we work hard to avoid zstd-in-RAM -> texture -> render incoherency which is cool, the network
Sometimes this results in flickering, sometimes it doesn't, but it always results in bad UX. I don't think delaying message handling is the right way to deal with potential flickering - given that tile updates happen entirely asynchronously, that's still no guarantee that they'd happen in the same frame.
Sure; it's some attempt to balance the stall-forever vs. flicker quandry 
From my limited debugging, I think we have issues around invalidations at the moment - If I update the background colour of a spreadsheet on a large enough screen, I see partial updates currently (which I don't see in LibreOffice). It doesn't really matter about the delay, there's always going to be a situation or a screen big enough to break the heuristics - I believe we have the metadata to just do the right thing without any heuristics.
Fair enough - if you have a better, cleaner and more consistent solution for the problem and we're both on the same page go for it =) Would just like to see the new solution/fix to replace the older one in one shot if possible 
ATB,
Michael.