[OLPC-Games] KuKu refactor for decreased playtime lag

Christopher Schmidt crschmidt at metacarta.com
Sun Aug 19 04:20:57 EDT 2007


KuKu currently lags significantly when using the arrow keys. With a
little bit of profiling and refactoring, I was able to decrease the
level of CPU time used by KuKu by a factor of 2 on my mac. Essentially,
only changed pieces of display are updated, rather than the whole grid
being updated every loop through the event loop, which was making the
gameplay quite difficult. 

In my experience, this turned the lag time from practicaly unplayable to
practically unnoticable.

I attempted to put together a patch with git, but when I git-cloned the
repo, it didn't come anywhere near to matching the code that is in the
current .xo from the wiki: Which one is more up to date/should I be
using? (I can port my patch over -- it's primarily to the main event
loop of the game only.)

How should I create a patch? Are there tests I should be running? 

I created https://dev.laptop.org/ticket/2900 to upload the patch, and
will put it there if anyone can help me figure out what I need to do to
create it.

http://crschmidt.net/olpc/KukuAnakula.xo is the current version of the
code I've written.
http://crschmidt.net/olpc/Kuku-original.profile.txt is the profiling
data before the rewrite.
http://crschmidt.net/olpc/Kuku-refactor.profile.txt is the profiling
data after.

This data is generated by hotshot, grepped for 'kuku' (insensitive).
Function call counts drop from 8614 in the original to 744 in the refactor,
for a 5 second game where I move the chicken to each of the squares.

Note that this was simply a small 'attack the largest numbers first'
approach -- it's possible that a more concentrated effort would be able
to determine more places where optimization is possible. Specifically, I
avoided optimizing the case where images are loaded, though I think my
changes to limit grid.draw() will also have the result of limiting the
image redraws I saw being a problem at one point.   

Looking forward to helping if my changes are acceptable.

Regards,
-- 
Christopher Schmidt
MetaCarta


More information about the Games mailing list