btzy1996 wrote:
From what I think the code is doing, it seems that someone realised iterating through all stations and edges is too slow to be done on every single tick, so (to prevent choppy scrolling/resizing) the delay is added to make OpenTTD only need to rebuild the cache once, at the end of the scroll/resize. It won't be related to the number of nodes/links on screen, but amount of work for rebuilding the cache is proportional to the number of nodes/links in total on the whole map. Am I correct?

That is pretty much the case, plus the cache is re-calculated periodically.
The details of how the delay is determined/handled have been changed recently.
Resizing without scrolling (for the main viewport at least) doesn't trigger a sooner cache rebuild, so the display is only updated after the next periodic update.
For reference some of the things which I've already done in this area are:
* For the smallmap: just cache the whole graph, most of it will be visible anyway
* For viewports: incrementally update the existing cache as necessary during scrolling or zooming, and cache a slightly larger area than the viewport area to give some margin
* Cache more node and edge details to avoid needing to recalculate them during drawing
* Better line visibility/clipping algorithm (for whether lines intersect the drawing area and should be cached and/or drawn)
* Some general improvements to the cache performance
They're in this repo:
https://github.com/JGRennison/OpenTTD-patches