Stefan Behnel wrote:
> Hi,
> 
> the ExprNodes.subexpr_nodes() method caches the values of children
> referenced in the "subexpr" attribute. However, it can easily get in the
> way of tree transforms that replace these subexpressions after they have
> been requested for the first time (e.g. during temp allocation). Two ways
> to deal with it:
> 
> a) remove the caching entirely. I'm not sure it's worth it anyway, since
> the list of subexpressions tends to be pretty short.
> 
> b) make the tree visitor a bit smarter so that it clears the cache on any
> change (assuming that it can detect changes).
> 
> Opinions?

Long-term, there's an option c):

c) Use a reverse iterator pattern, i.e. a parent can be requested to 
invoke a visitor on all its children, and this is written out manually 
for every node class. Like this:

class AddNode(BinopNode):
     def iterate_children(reverse_iterator):
         reverse_iterator.next(self.op1)
         reverse_iterator.next(self.op2)

Also you would have reverse_iterator.next_list(self.body)

This has about the same performance as a) currently (assuming that the 
cost of getattr(self, "attr") is about the same as the cost of 
self.attr), but when/if Cython itself is compiled it can be optimized 
using parallell pxds and/or annotations, and then c) will be *much* 
faster than either a) or b).

Given this aspect, I wonder whether it makes sense to invest lots of 
time in this (presumably minor) optimization now. And a) certainly has a 
simpler feel to it. So I lean towards a)

b) is certainly not difficult to pull off though. (It just makes for a 
more complicated program to maintain and debug.)

-- 
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to