# GML[SOLVED] How much slower is a fine grid?

#### Dr_Nomz

##### Member
I read in the manual that I can have the grid coarser or finer depending on my needs, but the more cells, the more processing power.

How is this calculated? Is it REALLY a lot more, or negligible? Does it matter depending on how many NPCs are or could be using the grid? And does it increase with room size?

Comparison I'm thinking of is 25px per cell vs 50px. (With a room size varying between 1k PX - 10k PX max)

#### RefresherTowel

##### Member
It entirely depends on what you are doing with it. It's literally just how many points have to be searched. If you are using a breadth-first search or something along those veins, you'll want to have as coarse a grid as possible, but if you're using A* to search it, then you can get a little more fine. Think of it this way:

Worst case scenario, you're searching through your grid for something (perhaps the shortest route between two points on the grid) and you're using a breadth-first search AND the two points are at the furthest possible distance apart. The search will have to search the entire grid to find it's target. In a 25x25 size grid (which is how wide and tall the grid is, it has nothing to do with the pixel size of each grid square), it will have to repeat it's search function 625 times, roughly to find the answer. In a 50x50 grid, it will have to search 2, 500 points. In a 500x500 grid, it will have to search 250, 000 points.

If you're using a more optimised search algorithm (like A*) the steps will very likely be a lot less than this, but just keep in mind that increasing the number of squares in your grid increases the search time fairly rapidly.

Also, the way you're talking about 25px vs 50px for grid size makes me think you're not quite understanding the way the grid size functions. The actual pixel size of your grid squares that you are going to draw is entirely irrelevant to the search speed. You can have a 10x10 grid where each grid square is 1000px*1000px and it will search through that grid lightning fast, whereas if you have a 1000x1000 grid where each grid square is 1px*1px it will take a long time to search through that grid. So what matters is not how many pixels your grid sections are, but how many individual x and y points exist in your grid data structure.

#### Dr_Nomz

##### Member
Oh that does look helpful, thank you.