diff options
Diffstat (limited to 'guide/_sources/porting.rst.txt')
-rw-r--r-- | guide/_sources/porting.rst.txt | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/guide/_sources/porting.rst.txt b/guide/_sources/porting.rst.txt index 3b79f47..b4b0914 100644 --- a/guide/_sources/porting.rst.txt +++ b/guide/_sources/porting.rst.txt @@ -53,10 +53,42 @@ Behavior after:: .. _django PR#14349: https://github.com/django/django/pull/14349 +Experimental Python implementations +=================================== + +PyPy +---- +PyPy is using JIT to run Python code which can result in significant +performance improvements in some workflows, but it could also penalize +other programs. + +In particular, calls to compiled extensions can penalize PyPy severely. +For this reason, it is generally recommended to skip building "speedup" +extensions for PyPy — in fact, upstream build systems frequently do that +automatically. A common approach is to combine checks for PyPy with +``native-extensions`` USE flag: + +.. code-block:: bash + + python_compile() { + if ! use native-extensions || [[ ${EPYTHON} == pypy3 ]]; then + local -x MULTIDICT_NO_EXTENSIONS=1 + fi + + distutils-r1_python_compile + } + +However, this does not imply that Python packages largely based +on C extensions should not be marked for PyPy3 compatibility. +For example, while packages such as Pandas can be less performant +under PyPy, they could be used as a part of larger program that overall +benefits from running under PyPy. + + .. index:: freethreading Freethreading CPython versions -============================== +------------------------------ CPython is used the so-called "global interpreter lock" to prevent multiple threads from executing Python code simultaneously. It was designed like this to simplify implementation, but at the cost of @@ -86,7 +118,13 @@ whether a C extension supports freethreading mode, grep the code for ``Py_MOD_GIL_NOT_USED``. CPython will also verbosely warn upon importing extensions without this support. -In general, do not add ``python3_13t`` to ``PYTHON_COMPAT`` +In general, do not add ``python3_13t`` to ``PYTHON_COMPAT`` in leaf +packages, unless they make use of multithreading and have real gain +from freethreaded versions — otherwise, it may actually be slower than +the regular variant. + +For dependency packages, add ``python3_13t`` only after explicitly +testing that the package in question works. Do not add it if the package in question installs extensions that do not support freethreading. This would penalize the setup, prevent proper testing and therefore defeat the purpose of separately specifying this target. |