QueuedConnectionReader.dataAvailable causing slowdown when no connections?

I was just working on fixing a strange slowdown that only seemed to occur when my game’s host had no clients connected. Using pstats, I was able to track the slowdown to dataAvailable within this task, and add a check for the particular case where I noticed the slowdown:

def reader_poll(self, task):
    err = False
    if len(self.connections) == 0: return task.cont#My fix
    while self.cReader.dataAvailable() and not err:
        err= self.proc_data()
    return task.cont

Why was dataAvailable causing me to lose ~ 25 fps when no connections were available? pStats said that all the frame time was inside dataAvailable itself…
Even if I’ve fixed the case I noticed, if I don’t understand why this was happening the same issue could happen in other cases.

1 Like