boskee / Minecraft

Simple Minecraft-inspired program using Python and Pyglet
MIT License
207 stars 33 forks source link

Optimize world.py using Cython. #36

Closed BertrandBordage closed 11 years ago

BertrandBordage commented 11 years ago

Voilà, some static typing.

I chose to do this on world.py because this file contains what consumes most CPU (apart from pyglet).

According to cProfile, during the same in-game time (60 seconds of rendered game), and on the same (large) world, while flying on different directions to force hundreds of sectors to load and unload, and with VISIBLE_SECTORS_RADIUS = 16 and DRAW_DISTANCE = 120.0:

what was taking time:

Model.initialize:

during game:

For now, I think that the main part of the game is enough optimized. Of course, there is still some little annoying freezes, but they are mainly due to a bad synchronization between the rendering and the queue. I'll work on that later.

So this is good news, because even when asking hundreds/thousands of chunks updates to the game in one minute, we still have 8.5 % of the time that is spent sleeping.

When doing nothing, 57 % of the time is spent sleeping!

So have fun and develop lots of outstanding features, performance will follow :)