Skip to content

Optimize update_keyword_args() function #72032

Closed

Description

@vstinner
BPO 27845
Nosy @vstinner, @serhiy-storchaka

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 2016-09-28.22:05:09.527>
created_at = <Date 2016-08-23.21:44:34.855>
labels = ['performance']
title = 'Optimize update_keyword_args() function'
updated_at = <Date 2016-09-28.22:05:09.526>
user = 'https://github.com/vstinner'

bugs.python.org fields:

activity = <Date 2016-09-28.22:05:09.526>
actor = 'serhiy.storchaka'
assignee = 'none'
closed = True
closed_date = <Date 2016-09-28.22:05:09.527>
closer = 'serhiy.storchaka'
components = []
creation = <Date 2016-08-23.21:44:34.855>
creator = 'vstinner'
dependencies = []
files = []
hgrepos = []
issue_num = 27845
keywords = []
message_count = 3.0
messages = ['273518', '273681', '276023']
nosy_count = 2.0
nosy_names = ['vstinner', 'serhiy.storchaka']
pr_nums = []
priority = 'normal'
resolution = 'out of date'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'performance'
url = 'https://bugs.python.org/issue27845'
versions = ['Python 3.6']

Activity

  1. vstinner commented on Aug 23, 2016

    @vstinner
    MemberAuthor

    In the review of my issue bpo-27830 "Add _PyObject_FastCallKeywords(): pass keyword arguments as (key, value) pairs", Antoine Pitrou wrote about _PyStack_AsDict():

    "It's a pity that you're doing two dict lookups per keyword argument.
    Another strategy would be to check that PyDict_Size() == nk at the end, and if not, try to find the duplicate keyword."

    https://bugs.python.org/review/27830/diff/18203/Objects/abstract.c#newcode2326_Objects/abstract.c:2326

    In fact, I simply copied code from update_keyword_args(), helper function used by do_call() and ext_do_call() in Python/ceval.c.

    This function is quite old, the last major change was made in 2001:
    ---
    changeset: 15711:2481b5fe86d6
    branch: legacy-trunk
    user: Jeremy Hylton <jeremy@alum.mit.edu>
    date: Wed Jan 03 23:52:36 2001 +0000
    files: Python/ceval.c
    description:
    Revised implementation of CALL_FUNCTION and friends.
    More revision still needed.

    (...)
    ---

    But this change just moved code. It looks like the real code was in fact added by this change made in 2000:
    ---
    changeset: 12082:603db0d0aed1
    branch: legacy-trunk
    user: Jeremy Hylton <jeremy@alum.mit.edu>
    date: Tue Mar 28 23:49:17 2000 +0000
    files: Grammar/Grammar Include/opcode.h Lib/dis.py Misc/ACKS Python/ceval.c Python/compile.c Python/graminit.c
    description:
    slightly modified version of Greg Ewing's extended call syntax patch

    executive summary:
    Instead of typing 'apply(f, args, kwargs)' you can type 'f(*arg, **kwargs)'.
    Some file-by-file details follow.

    (...)
    ---

  2. vstinner commented on Aug 25, 2016

    @vstinner
    MemberAuthor

    See also the issue bpo-27358: "BUILD_MAP_UNPACK_WITH_CALL is slow.

  3. vstinner commented on Sep 12, 2016

    @vstinner
    MemberAuthor

    _PyStack_AsDict() doesn't check anymore if keys are unique.

    BUILD_MAP_UNPACK and BUILD_MAP_UNPACK_WITH_CALL opcodes now use PyDict_Update() to combine mappings and _PyDictView_Intersect() to check if keys are unique.

    I don't know if there is still something to optimize. The opcode changed the method to C and Python functions (FASTCALL) changed a lot recently ;-)

    I suggest to close the issue.

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

    performancePerformance or resource usage

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions