Writing efficient graphics programs is an art - and one that we will barely touch on in class. To make things that are really complicated but still run well requires knowing some tricks.
This page has some notes on some of the basic concepts for achieving good performance. It is written in terms of THREE, but most of the “rules” apply generally. Learning this stuff is valuable because it is helpful for understanding how things work.
Most of the time, in CS559, what we want to do is limited enough that we don’t need to worry about performance too much. The graphics hardware is sufficiently capable that assignments run well without too much cause for concern. However, if you try to do something complex you can make things that will not run well. Especially because the grader might have a less capable computer.
Some general rules:
- Do all object creation before the animation loop begins.
- Only change things that should be changed.
- Move/change objects by transforming them, not by changing their vertices.
- Do not re-configure materials (change shaders) while things are running.
- Prefer a small number of objects (BufferGeometries) to lots of small objects.
- Be careful about having too many textures. Re-use textures as possible.
- Prefer a few bigger textures (an atlas) to many smaller ones. Put different textures together into a single image and select out the pieces that you need.
- Don’t make textures bigger than you need.
- Don’t make things more complicated than they need to be.