MAXScript FAQ > How To Make It Faster > Only calculate once if possible |
MAXScript does no code optimization. You must do your own optimizations.
Try to avoid running the same calculation more than once, or interrogating the same value in the same node more than once.
In another example, a typical example of a script that you want to be as fast as possible is a Particle Flow Script Operator. In a typical Script Operator, you usually go through all particles in the Particle Container of the current Event and perform some operations on each one of them.
The Proceed handler typically looks like
Note that the variable 'count', containing the number of particles to be processed, is evaluated only once and then used as the top limit of the i loop.
would be a bad idea, because in the case of 1 million particles, the expression pCont.NumParticles() will be evaluated 1 million times instead of just once!
Never get a single pixel when you can get a whole line
Cache freqeuntly used functions and objects