1

When a code is tail call optimized, is it superior in performance/complexity, consuming less CPU resources in relation to it's non-optimized counterpart, or does it only save memory and nothing else?

1
  • 1
    On modern machines saving memory is one of the best ways to improve performance. Commented Nov 10, 2012 at 15:01

1 Answer 1

3

It might be a good idea to consult a particular processor specification, but from the general point of view tail call elimination improves performance because

  • no new stack frame is allocated
  • the nested call retuns directly to the caller of the current call rather than to the current call and only then to the original caller
  • less memory allocation means better use of CPU cache
  • less memory allocation means better use of main memory that may need to be paged or loaded when the stack is too large

The modern processors can reduce the overhead caused by these operations though.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.