|
2 | 2 | Performance |
3 | 3 | =========== |
4 | 4 |
|
5 | | -Stuff |
| 5 | +When using a high level language such as Python for real time rendering we must |
| 6 | +be extra careful with the total time we spend in Python code every frame. |
| 7 | +At 60 frames per second we only have 16 milliseconds to get the job done. |
| 8 | +This is ignoring delays or blocks caused by OpenGL calls. |
| 9 | + |
| 10 | +.. Note:: |
| 11 | + |
| 12 | + How important performance is will of course depends on the project. |
| 13 | + Visualization for a scientific application doing some heavy |
| 14 | + calculations would probably not need to run at 60 fps. |
| 15 | + |
| 16 | +Probably the biggest enemy to performance in python is **memory allocation**. |
| 17 | + |
| 18 | +Try to avoid creating new objects every frame if possible. This includes |
| 19 | +all mutable data types such as lists, sets, dicts. |
| 20 | + |
| 21 | +Another area is updating buffer object data such as VBOs and |
| 22 | +Textures. If these are of a fairly small size it might not be a problem, |
| 23 | +but do not expect Python to be able to efficiently feed CPU-generated data |
| 24 | +to OpenGL. If this data comes from a library though ctypes and we |
| 25 | +can avoid allocating the memory for the buffer each frame we might be good, |
| 26 | +but this is not always easy to determine and will needs testing. |
| 27 | + |
| 28 | +Try to do as much as possible on the GPU. Use features like transform |
| 29 | +feedback to alter buffer data and use your creativity to find efficient |
| 30 | +solitions. |
| 31 | + |
| 32 | +Performance in rendering is not straight forward to measure in any language. |
| 33 | +Simply adding timers in the code will not really tell us much unless |
| 34 | +we also query OpenGL about the performance. |
| 35 | + |
| 36 | +We can also strive to do more with less. Rendering, in the end, is really just |
| 37 | +about creating illusions. |
0 commit comments