| 1 |
This optimization enables "malloc removal", which "explodes" |
| 2 |
allocations of structures which do not escape from the function they |
| 3 |
are allocated in into one or more additional local variables. |
| 4 |
|
| 5 |
An example. Consider this rather unlikely seeming code:: |
| 6 |
|
| 7 |
class C: |
| 8 |
pass |
| 9 |
def f(y): |
| 10 |
c = C() |
| 11 |
c.x = y |
| 12 |
return c.x |
| 13 |
|
| 14 |
Malloc removal will spot that the ``C`` object can never leave ``f`` |
| 15 |
and replace the above with code like this:: |
| 16 |
|
| 17 |
def f(y): |
| 18 |
_c__x = y |
| 19 |
return _c__x |
| 20 |
|
| 21 |
It is rare for code to be directly written in a way that allows this |
| 22 |
optimization to be useful, but inlining often results in opportunities |
| 23 |
for its use (and indeed, this is one of the main reasons PyPy does its |
| 24 |
own inlining rather than relying on the C compilers). |
| 25 |
|
| 26 |
For much more information about this and other optimizations you can |
| 27 |
read section 4.1 of the technical report on "Massive Parallelism and |
| 28 |
Translation Aspects" which you can find on the `Technical reports page |
| 29 |
<../index-report.html>`__. |