-
Notifications
You must be signed in to change notification settings - Fork 682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add PyDict_GetItem method to PyDict type binding #3964
Comments
For some context, I changed this in #3330. I removed the "infallible" version but perhaps that was too aggressive and we can bring it back with an awkward name and a strong recommendation not to use it except in performance sensitive cases. It's possible there are ways that we could make error handling overhead lighter, those would need exploration. |
Possibly relevant: in 3.13 we will have So a cleaner option might be to just optimise this method on 3.13 once available. |
Also for freethreaded Python |
This will be helpful in micro optimizations where we don't care about errors and we are okay to get
None
.The current implementation of
get_item
usesPyDict_GetItemWithError
which creates a little overhead while taking Python errors.pyo3/src/types/dict.rs
Lines 431 to 438 in dcba984
The overhead could be pretty displayed using flame graph:
The right side with
PyErr::take
could goneThe solution is to add new method
get_item_TBD
which will usePyDict_GetItem
insteadThe text was updated successfully, but these errors were encountered: