[Cython] local variable handling in generators
Stefan Behnel
stefan_ml at behnel.de
Mon May 23 20:39:27 CEST 2011
Robert Bradshaw, 23.05.2011 20:09:
> In any case, I'm -1 to deleting references once their no longer used,
> we must wait 'till the end of the function, and I'm not sure the
> savings would be that great either.
Agreed.
> In terms of packing/unpacking the variables onto the local C stack,
> until we have live variable analysis (and even then) it may still be
> more expensive in some cases than just leaving it there, right?
I agree that it can be substantially more expensive to write back *all*
variables on each yield, although it doesn't have to be. It largely depends
on the generator code.
However, once we really know which values change between yield calls, i.e.
which ones need to be stored away, it will actually be less expensive in
most cases. We currently pay the indirection penalty for each access, even
read access, whereas the C compiler can then keep important variables in
registers and only write them back once per yield.
Stefan
More information about the cython-devel
mailing list