Skip to content
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

Use PEP 590 vectorcall to speed up calls to filter() #87453

Closed
corona10 opened this issue Feb 21, 2021 · 7 comments
Closed

Use PEP 590 vectorcall to speed up calls to filter() #87453

corona10 opened this issue Feb 21, 2021 · 7 comments
Labels
3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@corona10
Copy link
Member

BPO 43287
Nosy @rhettinger, @vstinner, @corona10
PRs
  • bpo-43287: Use PEP 590 vectorcall to speed up filter() #24611
  • Files
  • filter_bench.py
  • 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 2021-03-10.16:40:19.794>
    created_at = <Date 2021-02-21.17:59:22.986>
    labels = ['interpreter-core', '3.10']
    title = 'Use PEP 590 vectorcall to speed up calls to filter()'
    updated_at = <Date 2021-03-10.16:40:19.794>
    user = 'https://github.com/corona10'

    bugs.python.org fields:

    activity = <Date 2021-03-10.16:40:19.794>
    actor = 'corona10'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-03-10.16:40:19.794>
    closer = 'corona10'
    components = ['Interpreter Core']
    creation = <Date 2021-02-21.17:59:22.986>
    creator = 'corona10'
    dependencies = []
    files = ['49825']
    hgrepos = []
    issue_num = 43287
    keywords = ['patch']
    message_count = 7.0
    messages = ['387469', '387470', '387482', '387490', '387493', '388355', '388443']
    nosy_count = 3.0
    nosy_names = ['rhettinger', 'vstinner', 'corona10']
    pr_nums = ['24611']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue43287'
    versions = ['Python 3.10']

    @corona10
    Copy link
    Member Author

    +--------------+--------+----------------------+
    | Benchmark | master | vectorcall |
    +==============+========+======================+
    | bench filter | 191 ns | 151 ns: 1.26x faster |
    +--------------+--------+----------------------+

    Like reversed(https://bugs.python.org/issue41922), it looks okay to update filter() to use PEP-590.

    @corona10 corona10 added 3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Feb 21, 2021
    @rhettinger
    Copy link
    Contributor

    +0 I don't see any downside.

    Note, the benchmark only times instantiation of the filter object. It doesn't actually run the iterator which is where most of the runtime cost is spent. So in actual code there is almost zero benefit. For example, add "list" to the statement: stmt="b = list(filter(lambda x: x % 2 == 0, a))" and the improvement disappears.

    @corona10
    Copy link
    Member Author

    +0 I don't see any downside.

    Thank you Raymond :)
    I agree with your view, At first, I thought that instantiation time reducing is also meaningful and we already applied PEP-590 for some of the types to reduce instantiation. (e.g range(), list(), dict(), bool(), reversed(), type()..)

    And also I thought that filter is one of the well-used features in Python so it was one of the candidates to apply from my sight. ;)

    But if this PR only consume maintenance cost, I am okay with not to apply it doesn't matter :)

    And happy new year Raymond(Sorry I am late ;) But the lunar new year was only 2weeks ago so not too late lol)

    @rhettinger
    Copy link
    Contributor

    Happy new year to you as well :-)

    @rhettinger
    Copy link
    Contributor

    FWIW, I don't think there is much of a maintenance burden; hence, the +0. You've already done the work.

    @vstinner
    Copy link
    Member

    vstinner commented Mar 9, 2021

    See also bpo-43447: "Generate vectorcall code to parse arguments using Argument Clinic".

    @corona10
    Copy link
    Member Author

    New changeset 9a9c11a by Dong-hee Na in branch 'master':
    bpo-43287: Use PEP-590 vectorcall to speed up filter() (GH-24611)
    9a9c11a

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants