Compiler Optimization

The optimizer is at an early stage and is disabled by default. Backwards compatability cannot be guaranteed at this point.

The optimizer is a tool for improving performance and reducing resource consumption. In this context, the terms performance and resource can apply across multiple dimensions, including but not limited to: compiled code size, scratch slot usage, opcode cost, etc.

Optimizer Usage

The compiler determines which optimizations to apply based on the provided OptimizeOptions object as shown in the code block below. The OptimizeOptions constructor receives a set of keyword arguments representing flags corresponding to particular optimizations. If arguments are not provided to the constructor or no OptimizeOptions object is passed to compileTeal then the default behavior is that no optimizations are applied.

Optimization Flag




A boolean describing whether or not scratch slot optimization should be applied.


optimize_options = OptimizeOptions(scratch_slots=True)
compileTeal(approval_program(), mode=Mode.Application, version=4, optimize=optimize_options)