[pypy-issue] Issue #3011: cpyext slow when calling Py_BuildValue("ii", 2048, 2049) (pypy/pypy)

mattip at bitbucket.org mattip at bitbucket.org
Tue Apr 30 09:52:38 EDT 2019


New issue 3011: cpyext slow when calling Py_BuildValue("ii", 2048, 2049)
https://bitbucket.org/pypy/pypy/issues/3011/cpyext-slow-when-calling-py_buildvalue-ii

mattip:

As can be seen in @antocuni 's \[benchmark repo\]\([https://github.com/antocuni/cpyext-benchmarks](https://github.com/antocuni/cpyext-benchmarks)\), the `simple.allocate_tuple` benchmark is much slower than CPython

| benchmark | cpython 2.7.11 | cpython 3.6.3 | pypy2 v7.1 | pypy3.6 v7.1.1 |
| --- | --- | --- | --- | --- |
| simple.noargs | 0.35 secs | 0.41 secs | 0.17 secs | 0.21 secs |
| simple.onearg\(None\) | 0.38 secs | 0.43 secs | 0.18 secs | 0.22 secs |
| simple.onearg\(i\) | 0.37 secs | 0.43 secs | 0.23 secs | 1.47 secs |
| simple.varargs | 0.54 secs | 0.58 secs | 0.40 secs | 0.53 secs |
| simple.allocate\_int | 0.38 secs | 0.51 secs | 1.08 secs | 1.09 secs |
| simple.allocate\_tuple | 0.64 secs | 0.90 secs | 5.63 secs | 7.19 secs |

`Py_BuildValue` is a very common c-api call. In cpyext the call goes to `do_mktuple` in modsupport.c, which calls `v = PyTupleNew(n)`, then fills the tuple with n calls to `obj = do_mkvalue; PyTuple_SET_ITEM(v, obj, i);`Any ideas how we could make this faster?




More information about the pypy-issue mailing list