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
C Fast path for namedtuple's property/itemgetter pair #76673
Comments
Attribute access for named tuples can be made as fast as attribute access of instances of classes with slots. All that is needed is a C subclass of property with it own __get__ that directly look's up the tuple field using PyTuple_GET_ITEM using an index stored in a C struct rather than as an integer object. |
Alternatively we could consider the way of optimizing property or itemgetter (or both). This may be more complex solution, but if the added complexity is not too large, this solution may be more preferable because it will speed up not only namedtuple. |
Joe Jevnik at already worked through attempts optimize property/itemgetter. There isn't much fruit left there. What I've outlined here should be several times faster. The code will end-up being very similar to the __get__ for member objects which is currently the fastest form of attribute access. |
Ah, right. property already is hardy optimized, and specialized version of itemgetter gives only around 35% of maximal speed up. |
Ned, I don't have time to finish this before 3.7b1. Will you approve for inclusion in 3.7b2? This isn't a user visible feature. It's goal is to bring named tuple attribute lookup performance up to parity with regular classes using __slots__. |
OK, it would be nice to get this in and the risk seems relatively low. Good luck! |
Deferred to 3.8 |
There are few post-commit tweaks in PR 11367:
|
See also bpo-35619. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: