First thing to do is identify exactly what is taking up the time in your mainloop. Gather simple stats and check which functions/mmethods take up high CPU time or are called often and have high average times. Concentrate on reducing these times or post them here.