Continuing with the performance improvements, this weekend I tackled a big slowdown issue with the map texture generator. In essence, once enough time has passed and the world is full of polities, about 40% of the app’s CPU usage would be used to modify the map texture to display on screen, which is terrible. This would happen only when certain data-heavy overlays, like the “General” overlay, where active.

The cause was simple: Even though the texture generator is supposed to only modify the pixels (or texels) associated with the cells that have been updated by the simulation, way too many cell update requests where being generated by the simulator at the same time. This happened mostly because every time a polity was updated, a cell update request would be queued to be handled by the texture generator for every single group in the polity (for a variety of reasons).

The solution I came up with is what I ended up dubbing the Cell Update Filter. It is basically a system that filters every texture refresh request for a single cell or group of cells sent by the simulator, only keeping those that are relevant in the active map overlay. This isn’t actually something completely original: Many graphics engines use render filtering systems (eg. layers) to filter between objects that need to be rendered and those that not at any given time. The main difference is that I use this system to filter updates to individual texels on a single image.

Here’s a full list of the settings I now use to filter cell updates (source code alert):