[do not merge] Consider removing isinstance check from trampoline #228
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pydust performs an isinstance check inside the Trampoline.unwrap function (called from
py.as(T, pyobj)
) since this provides a nice level of automatic type-checking when invoking functions from Python.Of course.... runtime type checking has a cost. It's not always desirable, and in the case of the
self
argument in instance/class methods it's kind of unnecessary.Currently Pydust types are all heap-allocated (vs static types) to allow us to compile for the limited ABI.
Our isinstance check delegates to the Python
ffi.PyObject_IsInstance
function, which requires us to give a PyType. We grab this PyType by performing an import of the extension module and grabbing the class object from that. I'm not sure if there's a better way for heap-allocated types? Maybe we insert some global state into our generated libraries that populates on first import? Open to any other ideas?This seems to address the performance issues in #226 , but ideally I'd like to:
py.as
when knowingly converting from PyObject to PyDust class struct. Provide fast conversion fromPyObject
to Pydust type struct #227