On 08/11/2015 03:50, Steven D'Aprano wrote:
On Sun, 8 Nov 2015 01:23 am, Marko Rauhamaa wrote:
Your point of view is really down-to-earth. It's slightly analogous to
protesting against Unicode because you only ever need ASCII.
I don't think so, but in any case, Bart is *way* oversimplifying the
potential optimizations available. Function inlining depends on the
function being small enough that inlining it does more good than harm, but
it doesn't require that f never changes.
I didn't really have function in-lining in mind (although once you are
sure a specific function will always be called, that is a possibility
for the compiler).
There are plenty of optimisations available if you know you are calling
a function, and the compiler can 'see' the source code:
* You don't need to check that 'f' in 'f(a,b,c)' is a function; it will be.
* You will know whether the number of arguments provided is correct or
not, and make adjustments at compile-time if not
* Where keyword parameters are used, this can also all be sorted out at
compile-time, rather than at runtime
* (And does Python still need to do a lookup for the name 'f'? I don't
know; the CPython sources are hard to follow. But in my interpreters,
this is never necessary at runtime.)
However, most functions will not be visible to the compiler because they
are in imported modules. A certain amount of work can be done when a
module is loaded, but this now starts to get complicated.
Even such simple things as constant folding are slightly controversial! If
you go back to older versions of Python, code like this:
x = 1 + 1
actually performed the addition at runtime, instead of being compiled to:
x = 2
Believe it or not, even something as simple as that remains controversial,
Actually, it's not so simple! If floating point expressions are
involved, the results can be different between compiler and runtime, if
the compilation is done on a separate machine. But this is only a
problem is byte-code is distributed rather than sources.
--
BartC
--
https://mail.python.org/mailman/listinfo/python-list