Increasing Performance when Searching for Interfaces and Methods

Searching for an interface and a method in an interface can be slow. Especially when calling the same method multiple times in a loop, for example in order to affect multiple vertices, faces, normals, objects etc., performance can decrease significantly.

To speed up access to methods in interfaces, you can let MAXScript search for the interface and method once and then access the method directly in the loop.

INSTEAD OF SAYING

for i = 1 to 100 do
myObject.edit_normals.setNormal i myNormals[i]

YOU SHOULD SAY

EN_setNormal = myObject.edit_normals.setNormal -- the method
for i = 1 to 100 do
EN_setNormal i myNormals[i]

This way, the required interface and method will be searched for just once, and then accessed directly multiple times in the loop without searching.

ANOTHER WAY (NOT AS FAST AS THE ABOVE) WOULD BE

EN_mod_i = myObject.edit_normals.EditNormalsMod -- the interface
for i = 1 to 100 do
EN_mod_i.setNormal i myNormals[i]

In this case, the interface will be searched for just once, but the method will be searched for multiple times. If you intend to access many methods from the same interface, this way would be still faster than searching for both interface and method inside the loop.

See Also