logoalt Hacker News

A tail calling interpreter for Python (already landed in CPython)

117 pointsby phsilvalast Monday at 7:12 AM82 commentsview on HN

Comments

riffraffyesterday at 6:44 AM

How does this differ from direct threading interpreters?

It seems like it solves the same problem (saving the function call overhead) and has the same downsides (requires non-standard compiler extensions)

EDIT: it seems the answer is that compilers do not play well with direct-threaded interpreters and they are able to perform more/better optimizations when looking at normal-sized functions rather than massive blocks

http://lua-users.org/lists/lua-l/2011-02/msg00742.html

show 3 replies
saidinesh5yesterday at 4:32 AM

Recent discussion: https://news.ycombinator.com/item?id=42999672

Do check out the articles in the top most comment.. about how tail call optimization gets you faster interpreters.

It completely eliminates the overhead of function calls in the generated machine code while you still your code modularly using functions.

show 2 replies
__syesterday at 1:12 PM

`return goto f()` syntax in C seems interesting

I had a similiar idea that Python could have `return from f()` to support tail calls without the issues raised about implicit tail calls

dammajyesterday at 8:36 AM

To read about the basics of tail calls optimization:

https://blog.reverberate.org/2021/04/21/musttail-efficient-i...

asicspyesterday at 4:12 AM

See also this little bit of discussion about a week back: https://news.ycombinator.com/item?id=42999672

thunkingdeepyesterday at 3:19 AM

This does NOT mean Python will get Tail Call Optimization, as Guido cannot be shown The Light, and has decided.

show 4 replies
VWWHFSfQyesterday at 4:27 AM

Will Python ever get fast? Or even _reasonably_ fast?

The answer is no, it will not. Instead they'll just keep adding more and more syntax. And more and more ways to do the same old things. And they'll say that if you want "fast" then write a native module that we can import and use.

So then what's the point? Is Python really just a glue language like all the rest?

show 4 replies