TileMap performance problem

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By talanis

Hello everyone.

I am currently trying to examine the runtime behaviour of TileMap because I had performance issues in a project. Godot version is 3.1.1-stable

I have set up a test project with a single scene containing only a TileMap. Its TileSet has exactly 1 tile (8x8 image texture, no collision shape) and collision layer/mask are set to 0. Now when I test the performance with varying map sizes I get the following:

50x50 tiles: ~150 fps
100x50 tiles: ~100 fps
100x100 tiles: ~50 fps

I am pretty new to godot and I definitely have no idea what kind of work TileMap has to do every frame so it can be drawn. But my intuition says that for a pretty static object like TileMap that slowdown seems a bit much. And while I was googling for that problem I found out that people are using much larger TileMaps.

Maybe that’s just how TileMap works and 10,000 tiles is simply too much for it to handle. But even if so, I would like to know why. As mentioned above, the map never changes and has no physics interaction so drawing it should be cheap, right?

Thanks a lot!

What are your system specs? Which renderer are you using? What is the value of the quadrant size property?
Also, how are you setting those tiles? By code or did you draw them in editor?

Zylann | 2019-10-30 13:50

:bust_in_silhouette: Reply From: Firty

I’m having the same problem. I am creating a mult-thread map generator. I did tests from 64x64 to 512x512. If active YSort above 256x256 is below 50fps. In 512x512 the engine crashes. Deactivating Ysort, I generated a 512x512 map running at 60fps, but soon black blocks start to appear. My conclusion is that the problem is in the memory management not in TileMap, because a 512x map without Ysort consumes 170Mb, while a 468x with Ysort almost reaches 400Mb, generating a lot of lag. There is something wrong with this YSort…
Ryzen 1600 / Gtx1060 / 16Gb

I tried to generate maps above 512x, it crashes in the generation process, probably because the Dictionary is too big to manage … I have 4 threads generating a dictionary, and then apply it on the Tilemap.

Firty | 2020-01-26 17:14

I changed Quadrant_size to 1 … It was the same as using YSort. I changed it to 32 (I’m using 32x32 blocks), the black blocks are gone, and the performance was great using 512x512, this using only 170Mb and running at 60fps.

Firty | 2020-01-26 17:25

:bust_in_silhouette: Reply From: Buni42

I had the same problem, I had 30 x 30 tiles and was getting ~60 fps. For anyone still interested, I just changed my strecth mode from viewport to 2d and got ~200 fps.
You can find stretch mode under projects settings > Display > Window > stretch > mode.