Skip to content

C Fast path for namedtuple's property/itemgetter pair #76673

Closed

Description

@rhettinger
BPO 32492
Nosy @rhettinger, @serhiy-storchaka, @miss-islington
PRs
  • bpo-32492: C Fast path for namedtuple's property/itemgetter pair #5100
  • bpo-32492: 1.6x speed up in namedtuple attribute access using C fast-path #10495
  • bpo-32492: Tweak _collections._tuplegetter. #11367
  • bpo-32492: Tweak _collections._tuplegetter. #11367
  • bpo-32492: Tweak _collections._tuplegetter. #11367
  • bpo-32492: Add missing whatsnew entries for itemgetter and namedtuple #11897
  • 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:

    assignee = None
    closed_at = <Date 2018-12-31.12:15:44.489>
    created_at = <Date 2018-01-04.18:05:43.360>
    labels = ['extension-modules', '3.8']
    title = "C Fast path for namedtuple's property/itemgetter pair"
    updated_at = <Date 2019-02-16.20:30:47.658>
    user = 'https://github.com/rhettinger'

    bugs.python.org fields:

    activity = <Date 2019-02-16.20:30:47.658>
    actor = 'ned.deily'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-12-31.12:15:44.489>
    closer = 'serhiy.storchaka'
    components = ['Extension Modules']
    creation = <Date 2018-01-04.18:05:43.360>
    creator = 'rhettinger'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 32492
    keywords = ['patch']
    message_count = 12.0
    messages = ['309477', '309478', '309481', '309486', '311168', '311171', '316822', '332747', '332754', '332755', '332813', '335712']
    nosy_count = 3.0
    nosy_names = ['rhettinger', 'serhiy.storchaka', 'miss-islington']
    pr_nums = ['5100', '10495', '11367', '11367', '11367', '11897']
    priority = None
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue32492'
    versions = ['Python 3.8']

    Activity

    1. rhettinger commented on Jan 4, 2018

      @rhettinger
      ContributorAuthor

      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.

    2. added
      3.7 (EOL)
      extension-modules
      on Jan 4, 2018
    3. serhiy-storchaka commented on Jan 4, 2018

      @serhiy-storchaka
      Member

      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.

    4. rhettinger commented on Jan 4, 2018

      @rhettinger
      ContributorAuthor

      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.

    5. serhiy-storchaka commented on Jan 4, 2018

      @serhiy-storchaka
      Member

      Ah, right. property already is hardy optimized, and specialized version of itemgetter gives only around 35% of maximal speed up.

    6. rhettinger commented on Jan 29, 2018

      @rhettinger
      ContributorAuthor

      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__.

    7. ned-deily commented on Jan 29, 2018

      @ned-deily
      Member

      OK, it would be nice to get this in and the risk seems relatively low. Good luck!

    8. ned-deily commented on May 16, 2018

      @ned-deily
      Member

      Deferred to 3.8

    9. rhettinger commented on Dec 30, 2018

      @rhettinger
      ContributorAuthor

      New changeset 3f5fc70 by Raymond Hettinger (Pablo Galindo) in branch 'master':
      bpo-32492: 1.6x speed up in namedtuple attribute access using C fast-path (bpo-10495)
      3f5fc70

    10. serhiy-storchaka commented on Dec 30, 2018

      @serhiy-storchaka
      Member

      There are few post-commit tweaks in PR 11367:

      • Removed the docstrings cache. I have not found significant difference, but this make the code simpler.
      • Improved tests. Merged test_doc_writable and test_namedtuple_can_mutate_doc_of_descriptors_independently in the single test, added tests for immutability, hashing, field descriptors and help(), and rewriting old checks that used eval().
      • Unified names of tp_descr_get and tp_descr_set functions. This will help to search implementations of custom descriptors.
    11. serhiy-storchaka commented on Dec 30, 2018

      @serhiy-storchaka
      Member

      See also bpo-35619.

    12. serhiy-storchaka commented on Dec 31, 2018

      @serhiy-storchaka
      Member

      New changeset 052b2df by Serhiy Storchaka in branch 'master':
      bpo-32492: Tweak _collections._tuplegetter. (GH-11367)
      052b2df

    13. miss-islington commented on Feb 16, 2019

      @miss-islington
      Contributor

      New changeset 63fa1cf by Miss Islington (bot) (Raymond Hettinger) in branch 'master':
      bpo-32492: Add missing whatsnew entries for itemgetter and namedtuple (GH-11897)
      63fa1cf

    14. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.8 (EOL)extension-modules

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions