Rhai includes an optimizer that tries to optimize a script after parsing. This can reduce resource utilization and increase execution speed.
Script optimization can be turned off via the
There are three levels of optimization:
The default is
// Turn on aggressive optimizations engine.set_optimization_level(rhai::OptimizationLevel::Full);
None is obvious – no optimization on the AST is performed.
Simple performs only relatively safe optimizations without causing side-effects (i.e. it only
relies on static analysis and built-in operators for constant standard types, and will not
perform any external function calls).
Full is much more aggressive, including calling external functions on constant arguments to
determine their results.
One benefit to this is that many more optimization opportunities arise, especially with regards to comparison operators.