Performance becomes an issue when working with large amounts of data and large numbers of objects. In such cases, you can improve the execution speed of graphics code by minimizing the effect of two factors that contribute to total execution time:
Object creation — Adding new graphics objects to a scene.
Screen updates — Updating the graphics model and sending changes to be rendered.
It is often possible to prevent these activities from dominating the total execution time of a particular programming pattern. Think of execution time as being the sum of a number of terms:
T execution time = T creating objects + T updating + (T calculations, etc)
The examples that follow show ways to minimize the time spent in object creation and updating the screen. In the preceding expression, the execution time does not include time spent in the actual rendering of the screen.
Profile your code and optimize algorithms, calculation, and
other bottlenecks that are specific to your application. Then determine
if the code is taking more time in object creation functions or
You can begin to optimize both operations, beginning with the larger
term in the total time equation.
Is your code:
Creating new objects instead of updating existing objects? See Judicious Object Creation.
Updating an object that has some percentage of static data? See Avoid Updating Static Data.
Searching for object handles. See Avoid Repeated Searches for Objects.
Rotating, translating, or scaling objects? See Transforming Objects Efficiently.
Querying and setting properties in the same loop? See Optimize Code for Getting and Setting Graphics Properties.