[Python-Dev] Scope object (Re: nonlocals() function?)

Steven D'Aprano steve at pearwood.info
Wed Apr 7 02:02:50 CEST 2010


On Tue, 6 Apr 2010 04:25:08 pm Cesare Di Mauro wrote:

> It will certainly. There's MUCH that can be optimized to let CPython
> squeeze more performance from static analysis (even a gross one) on
> locals.
[...]
> They are just "dummy" examples, but can make it clear how far
> optimizations can go with static analysis on locals. Python is a
> language that make it possible to use such analysis at compile time,
> and I think it is a very good thing.

I'm not opposed to the idea of optimisations in general (far from it!) 
but in case anyone is thinking about doing any work in this area, 
please be careful about floating point optimisations. E.g. given a float 
x, you can't assume that x*0 == 0. Nor can you assume that 0-x is the 
same as -x. (The second is *almost* always correct, except for one 
float value.)

See, for example, the various writings by Professor Kahan:

http://www.drdobbs.com/184410314
http://www.cs.berkeley.edu/~wkahan/

Most of the issues discussed apply to languages that deal with floats at 
a lower level than Python does, but still, simple minded optimizations 
will break corner cases no matter what language you use.



-- 
Steven D'Aprano


More information about the Python-Dev mailing list