Frequently Asked Questions > Writing Better and Faster Scripts > How To Make It Faster? >

# Cache frequently used functions and objects

MAXScript FAQ > How To Make It Faster > Cache frequently used functions and objects

You can store frequently used functions and objects in user variables to faster access.

TEST CASE:
    ep = converttopoly (mesh())    --node
    ep_bo = ep.baseobject      --ediable poly
    polyop_getvert = polyop.getvert    --structure method
    IEditablePoly = ep_bo.EditablePoly   --FPS interface
    IEditablePoly_GetNumMapChannels =
    IEditablePoly.GetNumMapChannels   --FPS interface

FOR 100,000 ITERATIONS:
    polyop.getvert ep 1    -- 470 msec.
    polyop_getvert ep 1    -- 79 msec.
    polyop.getvert ep_bo 1   -- 48 msec.
    polyop_getvert ep_bo 1   -- 0 msec.
    ep.EditablePoly.GetNumMapChannels() -- 76532 msec.
    ep.GetNumMapChannels()   -- 72141 msec.
    ep_bo.EditablePoly.GetNumMapChannels()-- 36688 msec.
    ep_bo.GetNumMapChannels()   -- 34219 msec.
    IEditablePoly.GetNumMapChannels() -- 6454 msec.
    IEditablePoly_GetNumMapChannels() -- 0 msec.

TEST CASE:
    gs = geosphere()
    gs_bo = gs.baseobject
    theBend = bend()
    addmodifier gs theBand

FOR 100,000 ITERATIONS:
    gs.radius     -- 718 msec.
    gs.baseobject.radius    -- 828 msec.
    gs_bo.radius      -- 688 msec.
    gs.modifiers[1].angle    -- 718 msec.
    gs.modifiers[#bend].angle   -- 1187 msec.
    theBend.angle     -- 609 msec.

#### See Also

- Increasing Performance when Searching for Interfaces and Methods

- Previous Tip

- Only calculate once if possible

- Next Tip

- Dice your data into smaller pieces