MATLAB Compiler    

Optimizing Arrays

Scalar Arrays

(fold_scalar_mxarrays) When this optimization is enabled, all constant, scalar-valued array operations are folded at compile time and are stored in a constant pool that is created once at program initialization time. Folding reduces the number of computations that are performed at runtime, thus improving runtime performance.

Scalar folding can dramatically improve the performance of code that is manipulating scalar arrays, but it makes the code less readable. For example,

If you compile this with the -O none option, you get

Compiling with -O none -O fold_scalar_mxarrays:on, gives

In the optimized case, this code uses _mxarray0_, which is initialized at program start-up to hold the correct value. All constants with the same value use the same mxArray variable in the constant pool.


 Optimization Bundles Nonscalar Arrays