[enhancement] PyPy improvement idea
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
A less horribly slow method would be to pre-compile the Python source code, not re-evaluating it from a string every time. Or to expand the Python code into a series of PyXxx() function calls, with something along the lines of PyObject_CallMethod(sys_module, "_getframe", PyLong_FromLong(1)) and some PyObject_GetAttrString() on the result.
I imagine you already know it, but the kind of check done here (for both CPython or PyPy) is quite hackish. I would guess the problem is that when the user writes BaseClassInCpp.method(self) it really invokes the derived method, which makes an infinite loop in the case of overloaded methods in Python that wants to call the parent implementation. It would be an API change, but couldn't BaseClassInCpp.method(self) always invoke the base class method (or the closest written in C++), which might be different from self.method()?
Originally posted by @arigo in https://github.com/pybind/pybind11/issues/2436#issuecomment-685671487
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the related discussion in issue #2436 and examine the current handling of overloaded methods for both CPython and PyPy. Compare the proposed precompiled or PyObject_CallMethod approaches with the BaseClassInCpp.method(self) behavior; done requires an agreed API design and an implementation path that avoids the reported recursive dispatch.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- backend-api-design, performance
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100