[rust-dev] tail-call performance issue?

Patrick Walton pwalton at mozilla.com
Wed Jan 25 10:46:33 PST 2012

On 1/25/12 10:42 AM, Matthew O'Connor wrote:
> Hi,
> I was reading https://github.com/mozilla/rust/wiki/Bikeshed-tailcall and
> wondered about the statement "Tail calls cannot be implemented in
> general without a serious performance hit for all calls". I've never
> heard this before. tjc speculated it had to do with decrementing
> refcounts on normal function returns, but our discussion didn't reveal
> any obvious reasons.
> What is the reason for this performance hit on all calls?

Pascal calling conventions versus C ones, basically. To handle tail 
calls in the case in which the callee has more arguments than the 
caller, you have to make sure that callees pop all their arguments (the 
Pascal convention). This prevents callers from reusing one set of 
outgoing argument space for all calls (the C convention).

I don't know what the performance hit is in practice; I suspect it's 
fairly small and not serious. I'm sure that one could make a 
microbenchmark that performs significantly worse under Pascal calling 
conventions than C ones, though.


More information about the Rust-dev mailing list