Slowness in C# with TileMapLayers

Godot Version

Stable 4.3 (Mono)

Question

How fast is C# in Godot? I have rewritten my minesweeper board solver in C# after I trashed my GDScript implementation of it for being too slow, and I keep finding that the thing is far too slow to bare. I am using multiple TileMapLayers for the board, and I have a suspicion that it is the source of the slowness. My code has a lot of SetCell() and GetCellSourceId() calls in it. I have the source code at Minesweeper board solver C# Godot - Pastebin.com, but I don’t know what I should do at this point. I have poured multiple months into trying to find a good solution to this problem, but I keep getting to dead ends.

Thanks for any help that anyone can provide me.

The answer to this question varies a lot. You can write C# code that is magnitudes slower than GDScript if you don’t know what you’re doing, and this can go the other way around.

Generally speaking, in certain tasks, C# is faster, while in others, GDScript is more efficient. I can point you to this video in this regard:

However, when it comes to your specific use case, use the built-in tools Godot offers (Monitor) to pinpoint which part of your code is the slowest, that should be your first step in figuring out what’s wrong.

1 Like

I don’t see these calls in the pastebin you provided, wondering how you are calling those on how large of a board, etc.

Is your minesweeper board solver’s purpose to be used to brute force generation of valid minesweeper boards through random chance?

If so lookup wave function collapse. You shouldn’t need to check if a board is valid, the generation constraints should define it as such and result in minimal if any retries

Edit: thought about this for a hot minute and realised you’re probably trying to create a version that is guaranteed solvable/first click allowed. WFC may still help, but honestly maybe not as the constraints probably aren’t localised.

you are right!