cairo-vm icon indicating copy to clipboard operation
cairo-vm copied to clipboard

Evaluate implementing tail-call optimization

Open Oppen opened this issue 3 years ago • 2 comments

Cairo programs tend to rely heavily on recursion. A common optimization in languages with similar behavior is converting tail calls into jumps. It's not certain that it makes sense or that it is possible with Cairo (for a start, its memory is read only, so we can't simply reuse the slots in the stack to store the arguments for the new "call", and it may alter traces as well), but if it's possible it could save memory and instructions to implement it.

Oppen avatar Jul 13 '22 12:07 Oppen

I think the original VM already does this. I will ping Lior to make sure we are not missing something, I think he told me the return() supports tail-call recusion.

unbalancedparentheses avatar Jul 25 '22 08:07 unbalancedparentheses

It does support tail-call recursion, but not necessarily tail-call optimization. I should check the source code.

Oppen avatar Jul 25 '22 14:07 Oppen