Reducing dropped frames in PsychoPy
There are many things that can affect the speed at which drawing is achieved on your computer. These include, but are probably not limited to; your graphics card, CPU, operating system, running programs, stimuli, and your code itself
Of these, the CPU and the OS appear to make rather little difference (except that the old PPC macs took a long time to start python). To determine whether you are actually dropping frames see here
Things to change on your system:
- make sure you have a good graphics card. Avoid integrated graphics chips, especially Intel integrated chips and especially on laptops because you don't get to change your mind so easily on a laptop. In particular, try to make sure that you card supports OpenGL 2.0
- shut down as many programs as you can, including background processes (e.g. anti-virus auto-updating)
- [OS X] Turn off TimeMachine backups
Writing optimal code
- run in full-screen mode (rather than simply filling the screen with your window). This way the OS doesn't have to spend time working out what application is currently getting keyboard/mouse events.
- after generating stimuli
- don't generate your stimuli when you need them. Generate them in advance and then just modify them later with the methods like setContrast(), setOrientation() etc...
- calls to the following functions are comparatively slow, because they require more cpu time than most other functions and then have to send a large amount of data to the graphics card. Try to use these methods in inter-trial intervals. This is especially true when you need to load an image from disk too as the texture.
- PatchStim.setTexture()
- RadialStim.setTexture()
- TextStim.setText()
- if you don't have OpenGL2.0 then calls to setContrast, setRGB and setOpacity will also be slow, because they also make a call to setTexture(). If you have shader support then this call is not necessary and a large speed increase will result.
- avoid loops in your python code (use numpy arrays to do maths with lots of elements)
- if you need to create a large number (e.g. greater than 10) similar stimuli, then try the ElementArrayStim
Possible good ideas (it isn't clear that these actually make a difference, but they might).
Do change this wiki or email the list if you have further info for these points
- disconnect the internet cable (to prevent programs performing auto-updates?)
- on Macs you can actually shut down the Finder. It might help. See Alex Holcombe's page
- use a single screen rather than two (probably there is some graphics card overhead in managing double the number of pixels?)
Things that PsychoPy will automatically attempt to do on your behalf (as of v1.00.05 unless stated):
- all systems: PsychoPy was built very much around the use of optimised hardware-accelerated graphics. The graphics card is made to do as much as possible, leaving the cpu relatively free
- win32:
- raise the priority of the thread with
SetPriorityClass and SetThreadPriority. (This was available long before v1.00 but had to be called manually with core.rush(3). As of v1.00.05 it happens automatically on window generation).
- OS X:
- The priority of the thread is raised with mach/thread_policy_set
- Code is synchronised to the frame refresh by measuring the current beam position of the monitor
- Linux:
- The priority of the thread is set to SCHED_RR using sched_setscheduler, but this only operates if the user runs the script with su permissions.