<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Python tail-optimisation using byteplay</title>
	<atom:link href="http://www.teamrubber.com/blog/python-tail-optimisation-using-byteplay/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.teamrubber.com/blog/python-tail-optimisation-using-byteplay/</link>
	<description>Team Rubber talks on the Internet in a blog</description>
	<lastBuildDate>Tue, 02 Mar 2010 18:34:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Damien Diederen</title>
		<link>http://www.teamrubber.com/blog/python-tail-optimisation-using-byteplay/comment-page-1/#comment-2319</link>
		<dc:creator>Damien Diederen</dc:creator>
		<pubDate>Tue, 21 Apr 2009 10:10:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.teamrubber.com/blog/?p=490#comment-2319</guid>
		<description>Hi Tim,

I&#039;ll keep you in the loop.  And yes, it&#039;s a pity we only support 3.x for now (we were not expecting to have an usable engine so “early,” and were hoping for a faster uptake of the new version).  In fact, that makes it very difficult for us to cut our teeth on real-world examples; I guess I&#039;ll just bite the bullet and integrate with 2.6 too.

CrossTwine Linker does not currently include a tracing JIT, it&#039;s more of a “classical” design.  I&#039;m not sure a tracing JIT buys you a lot on this particular front, though: the compiler still has to recognize the situation to be able to reuse frames (TANSTAAFL).  On the other hand, you are right that it might be able to automatically inline—and possibly coalesce—frame creation, and to peephole the sequence of returns away.

Truth to be told, TCO (and inlining in general) are not “free” optimizations, especially in a dynamic language where a program can examine (and manipulate!) its call stack at any time.  I&#039;ll probably hack the Python compiler to do analysis on a couple large applications before I venture down that path…

P.-S. — As you mentioned, your “factorial” function is not eligible for TCO, which would require an accumulator to be used.  I&#039;m not aware of any (non-research) compiler which does that kind of transformation behind the scenes, though, which leads me to think it&#039;s not worth the trouble.  (But then, I&#039;ve been wrong before. ;)</description>
		<content:encoded><![CDATA[<p>Hi Tim,</p>
<p>I&#8217;ll keep you in the loop.  And yes, it&#8217;s a pity we only support 3.x for now (we were not expecting to have an usable engine so “early,” and were hoping for a faster uptake of the new version).  In fact, that makes it very difficult for us to cut our teeth on real-world examples; I guess I&#8217;ll just bite the bullet and integrate with 2.6 too.</p>
<p>CrossTwine Linker does not currently include a tracing JIT, it&#8217;s more of a “classical” design.  I&#8217;m not sure a tracing JIT buys you a lot on this particular front, though: the compiler still has to recognize the situation to be able to reuse frames (TANSTAAFL).  On the other hand, you are right that it might be able to automatically inline—and possibly coalesce—frame creation, and to peephole the sequence of returns away.</p>
<p>Truth to be told, TCO (and inlining in general) are not “free” optimizations, especially in a dynamic language where a program can examine (and manipulate!) its call stack at any time.  I&#8217;ll probably hack the Python compiler to do analysis on a couple large applications before I venture down that path…</p>
<p>P.-S. — As you mentioned, your “factorial” function is not eligible for TCO, which would require an accumulator to be used.  I&#8217;m not aware of any (non-research) compiler which does that kind of transformation behind the scenes, though, which leads me to think it&#8217;s not worth the trouble.  (But then, I&#8217;ve been wrong before. <img src='http://www.teamrubber.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: timw</title>
		<link>http://www.teamrubber.com/blog/python-tail-optimisation-using-byteplay/comment-page-1/#comment-2318</link>
		<dc:creator>timw</dc:creator>
		<pubDate>Tue, 21 Apr 2009 00:53:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.teamrubber.com/blog/?p=490#comment-2318</guid>
		<description>I&#039;d definitely be interested in hearing your results. 

For what it&#039;s worth, these results were on python 2.6.

Crosstwine looks interesting, but unfortunately bytecodehacks isn&#039;t available for python 3 (and 2to3 hasn&#039;t managed an automatic conversion), so I haven&#039;t been able to quickly test if this still offers a performance increase on crosstwine.

I don&#039;t know what kind of JIT you are using, but I think that a tracing JIT could be modified automatically do most of the optimisation I&#039;ve done - I started having a look at the tracing JIT in the newest version of pypy to see if it does, but I haven&#039;t managed to get my head around the code well enough yet.

I&#039;m afraid I don&#039;t have any stats about how often tail-recursive calls are likely to be used, although there is also the wider variety of calls that could be converted to one. 

e.g.
def f(x):
  return x*f(x-1)

(which can easily be converted to the lisp-like version used above)</description>
		<content:encoded><![CDATA[<p>I&#8217;d definitely be interested in hearing your results. </p>
<p>For what it&#8217;s worth, these results were on python 2.6.</p>
<p>Crosstwine looks interesting, but unfortunately bytecodehacks isn&#8217;t available for python 3 (and 2to3 hasn&#8217;t managed an automatic conversion), so I haven&#8217;t been able to quickly test if this still offers a performance increase on crosstwine.</p>
<p>I don&#8217;t know what kind of JIT you are using, but I think that a tracing JIT could be modified automatically do most of the optimisation I&#8217;ve done &#8211; I started having a look at the tracing JIT in the newest version of pypy to see if it does, but I haven&#8217;t managed to get my head around the code well enough yet.</p>
<p>I&#8217;m afraid I don&#8217;t have any stats about how often tail-recursive calls are likely to be used, although there is also the wider variety of calls that could be converted to one. </p>
<p>e.g.<br />
def f(x):<br />
  return x*f(x-1)</p>
<p>(which can easily be converted to the lisp-like version used above)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Damien Diederen</title>
		<link>http://www.teamrubber.com/blog/python-tail-optimisation-using-byteplay/comment-page-1/#comment-2317</link>
		<dc:creator>Damien Diederen</dc:creator>
		<pubDate>Mon, 20 Apr 2009 23:36:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.teamrubber.com/blog/?p=490#comment-2317</guid>
		<description>Interesting experiment!

Even though I believe tail-recursive calls are pretty rare in real-world scenarios, it would be interesting to know which percentage of the calls are eligible for TCO in a typical Python program. Would you happen to have the numbers at hand?

Also, reusing the frame is not going to be possible when it is not wide enough to hold all the variables of the callee.  I&#039;ll probably toy a bit with the idea in our Python JIT when I get the opportunity; tell me if you would like to hear about the results.</description>
		<content:encoded><![CDATA[<p>Interesting experiment!</p>
<p>Even though I believe tail-recursive calls are pretty rare in real-world scenarios, it would be interesting to know which percentage of the calls are eligible for TCO in a typical Python program. Would you happen to have the numbers at hand?</p>
<p>Also, reusing the frame is not going to be possible when it is not wide enough to hold all the variables of the callee.  I&#8217;ll probably toy a bit with the idea in our Python JIT when I get the opportunity; tell me if you would like to hear about the results.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
