|
|
= Speeding up cpyext =
|
|
|
|
|
|
(this page is of historical importance only, we now track any PyObject with a w_obj and link them using gc hooks)
|
|
|
|
|
|
cpyext is PyPy's emulation of the CPython C-API. It allows PyPy to integrate CPython extension modules. Emulating this API involves a certain overhead that results in it being slower (and sometimes substantially slower) than the native C-API in CPython.
|
|
|
|
|
|
This page collects ideas on how to speed up this emulation.
|
|
|
|
|
|
* Use a weak dictionary to cache the PyObject representation of each PyPy object that has been passed into C space already in order to avoid a) allocation overhead and b) the PyObject dying while the PyPy object is still alive.
|
|
|
|
|
|
* Use a free-list for PyObject representations of objects to avoid memory allocation overhead.
|
|
|
|
|
|
* Reuse PyObject struct of an input object to the PyNumber_InPlace*() functions if its refcount is 1 (may conflict with the weak-dict optimisation). |