[pypy-issue] Issue #2779: Performance loss with deeply nested generators (pypy/pypy)
issues-reply at bitbucket.org
Thu Mar 29 17:25:56 EDT 2018
New issue 2779: Performance loss with deeply nested generators
PyPy (5.10.1) is significantly slower than CPython (3.6.3) on the attached benchmark.
The script profiles traversing generators nested with `yield from` at various depths, which also comes up when suspending and resuming recursive or nested `async` functions. I was curious whether PyPy optimizes `yield from` delegation as mentioned [in the original PEP](https://www.python.org/dev/peps/pep-0380/#optimisations) and later in a [message by Guido](https://groups.google.com/forum/#!msg/python-tulip/bmphRrryuFk/BNEOOOuR1j4J). It seems that CPython [dropped](https://bugs.python.org/issue14230) the optimization due to an issue with tracebacks.
It looks like PyPy doesn't implement the optimization either - but that is not the topic of this issue. I noticed a sharp slowdown in PyPy at the nesting depth of around 80. At that point the performance suddenly drops to levels significantly slower than CPython. For example, on my machine, with depth == 100:
$ python3 benchnestedyield.py 100
$ pypy3 benchnestedyield.py 100
$ pypy3 --jit off benchnestedyield.py 100
With depth == 50, the numbers look like something I'd expect when comparing PyPy and CPython:
$ python3 benchnestedyield.py 50
$ pypy3 benchnestedyield.py 50
$ pypy3 --jit off benchnestedyield.py 50
This is probably not a big issue in practice, but I wanted to report it in case it's an anomaly someone cares to investigate.
More information about the pypy-issue