Skip to content

Tail Call Optimization

Martin Karing edited this page Nov 23, 2019 · 2 revisions

ID: tail call
Availability: ConfuserEx 2

This optimization is able to optimize methods that call another method as the last thing before the return and methods that use tail recursion.

Parameter

  • tailRecursion: This parameter is a boolean value indicating if tail recursions should be converted to a loop.
    • true: Convert tail recursions to loops. (default)
    • false: Don't apply the special optimization to tail recursions and just mark these calls as tail calls, like any other tail call.

Example

<protection id="tail call">
  <argument name="tailRecursion" value="true" />
</protection>

Remarks

This optimization is safe to be used in all cases. It increases the size of the assembly very slightly and decreases the memory usage on the stack. The optimization adds the Tailcall code to all tail calls. This allows the .NET Runtime to discard the stack frame of the current method, before calling the next method.

The additional tail recursion optimization, turns methods that do a recursive call as last operation into loops. This is in general safe, unless the depth of the stacktrace is relevant.