[−][src]Module fasteval::compiler
This module compiles parsed Expression
s into an optimized AST node called an Instruction
.
The compiled form is much faster, especially for constants.
Compile-time Optimizations
Constant Folding
Operations with constants can be calculated at compile time so
they don't need to be calculated during eval()
.
For example, 1 + x + 1
will be compiled into x + 2
, saving some time during eval()
.
If the entire expression only consists of constants (no variables),
then the expression can be reduced to a final result at compile time,
resulting in near-native speed during eval()
.
Algebraic Simplification
- Subtraction is converted to Addition.
- Division is converted to Multiplication.
- Built-in functions with constant arguments are evaluated.
- Constant terms are combined.
- Logical operator short-circuits are applied and no-op branches are discarded.
Optimized Memory Layout and Execution
- Variable-length
Expression
/Value
AST nodes are converted into constant-sizedInstruction
nodes. - The
IC
enumeration helps to eliminate expensive function calls.
Structs
InstructionI | An |
Enums
IC | This enumeration boosts performance because it eliminates expensive function calls for constant values. |
Instruction | An |
Traits
Compiler | You must |