Next: 5.1.4 Representation of Objects
Up: 5.1 Advanced Compiler Introduction
Previous: 5.1.2 Optimization
The sort of symbolic programs generally written in Common Lisp often
favor recursion over iteration, or have inner loops so complex that
they involve multiple function calls. Such programs spend a larger
fraction of their time doing function calls than is the norm in other
languages; for this reason Common Lisp implementations strive to make the
general (or full) function call as inexpensive as possible. Python
goes beyond this by providing two good alternatives to full call:
- Local call resolves function references at compile time,
allowing better calling sequences and optimization across function
calls. See section 5.6.
- Inline expansion totally eliminates call overhead and allows
many context dependent optimizations. This provides a safe and
efficient implementation of operations with function semantics,
eliminating the need for error-prone macro definitions or manual
case analysis. Although most Common Lisp implementations support
inline expansion, it becomes a more powerful tool with Python's
source level optimization. See sections 5.4
and 5.8.
Generally, Python provides simple implementations for simple uses
of function call, rather than having only a single calling convention.
These features allow a more natural programming style:
- Proper tail recursion. See section 5.5
- Relatively efficient closures.
- A funcall that is as efficient as normal named call.
- Calls to local functions such as from labels are
optimized:
- Control transfer is a direct jump.
- The closure environment is passed in registers rather than heap
allocated.
- Keyword arguments and multiple values are implemented more
efficiently.
See section 5.6.
Raymond Toy
Mon Jul 14 09:11:27 EDT 1997