Decreasing performance over the time (Python)


I’m trying to make a pathfinding system with jump point search algorithm.

I don’t know why, when you select all players and you travel on the map, performances decrease over the time.

I haven’t found where is the problem. When player has reached destination or when right mouse button is pressed, the program deletes lists and variables with “del”, reinitialize some other things…

  1. Do you know a tool to identify where is the problem?

2)Or could you test the .blend and take a look at my code to try to find where is my mistake?

3)Or more generally, can you tell me what can cause such decreasings of performances over the time in programs?

I thank you very much for your help!
The .blend:

PS: Don’t pay attention to weird movements of the players. Pathfinding system is not finished…

I do not know where your code is inefficient, but I can confirm it is.

Here is some code that helps you identifying the lag:

import bge
import time

def showlags(controller):
    owner = controller.owner
    frame = owner.get("frame",0)
    owner["frame"] = frame
    lastTime = owner.get("time")
    currentTime = time.clock()
    owner["time"] = currentTime
    if not lastTime:
    delta = currentTime - lastTime
    if delta > 0.17:
        print( "lag at", frame, "seconds:",delta)

Unfortunately your code is a bit to large for a quick review. You have quite a lot of loops. They do not seem to be that long, so it is ok. You should keep in mind this code runs all the time. But as you do not have a constant lag you can care for that later.

I think I noticed the lag happens when right clicking. So I suggest to check the processing path when this happens. I guess there are some loops with O(n²) or worse. From my point of view the pathfinding is the bottleneck.

Thank you very much Monster! And thank you for your code even if I didn’t use it. But you put me on the path to resolve the problem. Actually, there was an issue when right click in the pathfinding process. I forgot to clean a list which became larger and larger (own[“nodesToClean”]). Now I think there is no more decreasing performances:

PS: Also thank you for all your works and tutorials on Blender.