I have finished implementing A* pathfinding in my game. Here's the situation: (If I don't give a situation, everyone's going to give generic contexts and generic answers.)
Before implementation: The game is running smoothly at 60FPS. The game itself is simple, all thanks to easy grid movements for moving entities.
After implementation: The game is now lagging badly and it's unacceptable. The only thing I know that's causing the lag is the Map of nodes, in which the size is 160x120. Every 256 + X game ticks, once a unit entity spawns, it calls upon the pathfinding system to create a path that lets the unit entity to go from point A to point B. The X is arbitrary, since the player has to click on the screen to place down the spawners, which they automatically initiate themselves. At 60FPS, that's about every 4 to 5 seconds, the pathfinding system starts execution, which may lasts several seconds, due to the size of the nodes.
I heard many things about debugging code, such as profiling, logging, and simple step in/step out with breakpoints. Of the first two, I only know how to debug codes with the last option. Perhaps maybe if I do profiling, I might be able to see where the game is lagging, and then ask for more help on what I should do to solve it.
Of course, the most obvious solution is to cut down the number of nodes in the map. Unfortunately, each node is also binded to a color value. All nodes are pixel data taken from a BufferedImage, or in this case, a Canvas. So, I can't just edit out the size. Otherwise, I would have to do a complete rewrite, and I want to avoid that by all means, unless it's absolutely necessary. Speaking of A*, maybe I could adapt the algorithm so that it uses a greedy method of approach, but I don't have the knowledge to do such a thing, let alone tweaking the heuristics. I'm such a noobie here.
And how do you supposed to know when you're supposed to delegate the task (A* algorithm) into a concurrent task, and how to go from there? I don't have that much experiences with concurrency, so I hoped to hear what experienced experts would say about this.