Large 2d tilemap causes 4-5ms lag on setcell invocation

Godot Version

4.5

Question

I’m working on a top-down farming/simulation style game with a pretty large tilemap (700x700 tiles / 490,000) and there is extremely noticeable lag when I call setcell (4-5ms per frame). I have tried both terrain connect (which is slightly worse than setcell) but even a raw setcell (on a single tile) causes fps to plummet.

I’m trying to get some guidance before I do a large technical refactor. Some posts online seem to suggest that breaking this down into smaller tilemap chunks might provide better performance gains, but this would be quite a bit of work at this point so I’d like a better understanding before I commit to a weekend-long refactor.

I’m wondering if there’s something I could be overlooking in the meantime? Or if having say 100 tilemap layers of 5,000 tiles each is the better way to go.

This post Lag issue with set_cells_terrain_connect seems to mention it but never got resolved.

My cpp is rusty, but trying to look through the source:

I’m assuming this is because the single set_cell is still forcing an internal update, and on such a large resource, this is the problem?

Did you change the TileMapLayer.rendering_quadrant_size or enabled CanvasItem.y_sort_enabled? The quadrant size is a rendering optimization so changing it to a lower value or enabling y-sort (it forces it to 1) will affect performance every time the tilemap is changed.

Do you have physics or navigation layers in your TileSet? Modifying the tilemap will also modify the underlying shapes and polygons so it will take more time too.

1 Like

I do have physics layers but not navigation.

Interestingly, if I uncheck “Occlusion Enabled” and “Collision Enabled”, the lows go down to like 40fps and it lasts for a long time.

Here’s some experiments with rendering quadrant size (fps isn’t ACTUAL I’m just trying to illustrate the jitter severity versus duration):
1 - Unplayable
4 - Jitter is mild, but lasts incredibly long and stacks up | fps avg: 80, highs: 80, lows: 80
8 - Jitter is noticeable, but lasts longer | fps avg: 160, lows: 140, highs: 160
16 - Jitter is sharper, but over faster | fps avg: 180, lows: 120, highs: 180
32 - Jitter is extremely sharp, but over quickly | fps avg: 180, lows: 100, highs: 180

So I’m at a bit of a loss, I actually enabled navigation and it seems like the jitter got significantly better? It’s barely perceptible at this point.

I would think that enabling occlusion, physics, and navigation would actually be worse for performance not better?