Why is Flee faster?

Nov 6, 2007 at 3:21 PM
Hi Eugene,

If you have a minute, could you help me understand why Flee is so much faster than FormulaEngine? I don't understand why emitting your own IL is faster than letting the CLR emit IL. It seems like your FormulaEngine just passes off to the .NET Math libs anyway.

Thanks,
Dustin
Coordinator
Nov 6, 2007 at 8:04 PM
>I don't understand why emitting your own IL is faster than letting the CLR emit IL.
The CLR is still emitting the IL, it's just that it's doing it at runtime to memory instead of at compile time to an assembly.

>could you help me understand why Flee is so much faster than FormulaEngine?
FormulaEngine is interpreted, which means that every time you evaluate an expression, code runs to unpack arguments, check their validity, choose an operation to perform (addition, function call), perform it (setup arguments, etc), and return the result. This adds up to a lot of overhead that, no matter how much you optimize, will always be present.

When a Flee expression is compiled, it generates IL which is then translated by the CLR into native processor instructions. This means that an expression like 1 + 2 basically amounts to loading two registers and performing an ADD instruction. The amount of overhead is the minimum required to run a program + the indirect call to the delegate pointing to the compiled expression.

The method that Flee uses will basically give you the fastest evaluation speed possible in .NET. The only ways to make it faster are to statically compile the code (thus losing the dynamic aspect) or optimize the emitted IL.