pybind/pybind11

[enhancement] PyPy improvement idea

Open

#2549 opened on Oct 5, 2020

View on GitHub
 (1 comment) (0 reactions) (0 assignees)C++ (14,677 stars) (2,005 forks)batch import
enhancementhelp wanted

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