Skip to content

Faster positional arguments parsing in PyArg_ParseTupleAndKeywords #73215

Description

@serhiy-storchaka
BPO 29029
Nosy @vstinner, @methane, @serhiy-storchaka
Files
  • PyArg_ParseTupleAndKeywords-faster-positional-args-parse.patch
  • PyArg_ParseTupleAndKeywords-faster-positional-args-parse-2.patch
  • 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 2017-01-17.08:15:00.665>
    created_at = <Date 2016-12-20.21:30:18.353>
    labels = ['interpreter-core', '3.7', 'performance']
    title = 'Faster positional arguments parsing in PyArg_ParseTupleAndKeywords'
    updated_at = <Date 2017-01-17.08:15:00.664>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2017-01-17.08:15:00.664>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-01-17.08:15:00.665>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core']
    creation = <Date 2016-12-20.21:30:18.353>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = ['45977', '46307']
    hgrepos = []
    issue_num = 29029
    keywords = ['patch']
    message_count = 8.0
    messages = ['283711', '285515', '285590', '285591', '285592', '285617', '285621', '285622']
    nosy_count = 4.0
    nosy_names = ['vstinner', 'methane', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'performance'
    url = 'https://bugs.python.org/issue29029'
    versions = ['Python 3.7']

    Activity

    1. serhiy-storchaka commented on Dec 20, 2016

      @serhiy-storchaka
      MemberAuthor

      Proposed patch speeds up parsing positional arguments in PyArg_ParseTupleAndKeywords().

      $ ./python -m perf timeit "1 .to_bytes(1, 'little', signed=False)"
      Unpatched:  Median +- std dev: 2.01 us +- 0.09 us
      Patched:    Median +- std dev: 1.23 us +- 0.03 us

      Currently names of all passed positional argument are looked up in the kwargs dictionary for checking if the argument is passed as positional and keyword argument. With the patch this is checked only if there are unhandled keyword arguments after parsing keyword arguments that don't passed as positional arguments.

      The same optimization also is applied to _PyArg_ParseTupleAndKeywordsFast() and like, but the effect is much smaller.

      The patch also includes tiny refactoring.

    2. methane commented on Jan 15, 2017

      @methane
      Member

      LGTM

    3. python-dev commented on Jan 16, 2017

      python-devmannequin
      Mannequin

      New changeset a36e60c5fee0 by Victor Stinner in branch 'default':
      Rename keywords to kwargs in getargs.c
      https://hg.python.org/cpython/rev/a36e60c5fee0

    4. vstinner commented on Jan 16, 2017

      @vstinner
      Member

      Oh, I missed this issue. Since I made minor cleanup recently, I took the liberty of rebasing your patch.

      I also pushed your "keywords => kwargs" change, just to make the patch simpler to review.

    5. vstinner commented on Jan 16, 2017

      @vstinner
      Member

      Unpatched: Median +- std dev: 2.01 us +- 0.09 us
      Patched: Median +- std dev: 1.23 us +- 0.03 us

      Oh wow, impressive speedup! As usual, good job Serhiy ;-)

      PyArg_ParseTupleAndKeywords-faster-positional-args-parse-2.patch: LGTM! Can you please push it?

    6. methane commented on Jan 17, 2017

      @methane
      Member

      LGTM again.

    7. python-dev commented on Jan 17, 2017

      python-devmannequin
      Mannequin

      New changeset a8563ef0eb8a by Serhiy Storchaka in branch 'default':
      Issue bpo-29029: Speed up processing positional arguments in
      https://hg.python.org/cpython/rev/a8563ef0eb8a

    8. serhiy-storchaka commented on Jan 17, 2017

      @serhiy-storchaka
      MemberAuthor

      Thank you for your reviews Inada and Victor. Thank you for rebasing the patch Victor.

      I were going first to try an alternative patch, maybe less efficient, but allowing to share more code. But since the code is changed so fast, it is better to commit the ready patch.

    9. 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.7 (EOL)end of lifeinterpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usage

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions