Skip to content

Performance of FromPyObject::extract #2968

Answered by adamreichold
hombit asked this question in Questions
Discussion options

You must be logged in to vote

This is a known foot gun of how the FromPyObject trait is defined insofar it has to return a PyResult whereas downcast returns a Result<_, PyDowncastErr>. Wrapping up the PyDowncastErr into a PyErr is the cost you are seeing.

The best workaround at the moment is to manually call downcast in if-let-else-if-let chains. Note that PyReadonlyArray is not a valid target for downcast though, i.e. you would need to downcast into PyArray first and then manually call readonly on it.

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@hombit
Comment options

@adamreichold
Comment options

@hombit
Comment options

@davidhewitt
Comment options

@hombit
Comment options

Answer selected by hombit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants