Skip to content

Seemingly unnecessary complexification of foo(**kw) #86199

Open

Description

@masklinn
mannequin
BPO 42033
Nosy @masklinn, @markshannon, @serhiy-storchaka, @MojoVampire, @brandtbucher

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 = 'https://github.com/markshannon'
closed_at = None
created_at = <Date 2020-10-14.10:48:31.902>
labels = ['3.9']
title = 'Seemingly unnecessary complexification of foo(**kw)'
updated_at = <Date 2020-12-16.14:34:05.732>
user = 'https://github.com/masklinn'

bugs.python.org fields:

activity = <Date 2020-12-16.14:34:05.732>
actor = 'josh.r'
assignee = 'Mark.Shannon'
closed = False
closed_date = None
closer = None
components = []
creation = <Date 2020-10-14.10:48:31.902>
creator = 'xmorel'
dependencies = []
files = []
hgrepos = []
issue_num = 42033
keywords = []
message_count = 5.0
messages = ['378613', '378667', '378674', '378686', '383172']
nosy_count = 5.0
nosy_names = ['xmorel', 'Mark.Shannon', 'serhiy.storchaka', 'josh.r', 'brandtbucher']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = None
url = 'https://bugs.python.org/issue42033'
versions = ['Python 3.9']

Linked PRs

Activity

  1. markshannon commented on May 3, 2022

    @markshannon
    Member

    I measured your PR on our benchmarking machine and saw no significant difference in performance. Which is what I would expect. It should be a tiny bit faster, but by such a small amount on the macro benchmarks that it would be hard to measure.

  2. MojoVampire commented on May 3, 2022

    @MojoVampire
    Contributor

    Huh. I'll admit there didn't seem to be any reason for it to be that much faster (I expected the primary beneficiary of this change to be stuff that accepts **kwargs to forward on to an internal call, e.g. in an overridden method like __init__ in inheritance hierarchies that accepts and forward s**kwargs to their parent class), so seeing that much benefit was surprising. Sad that it was illusory (or maybe only shows up on certain systems?).

    I haven't the foggiest notion why it would only show up on my machine. Granted, I run a weird setup (Alpine Linux on WSLv2), and maybe having stuff open in the background caused some jitter, but it's weird that the jitter would almost exclusively favor my patched code. shrugs The change to PyObject_Call seems necessary for correctness regardless (imposing a small, but unavoidable, performance loss in an uncommon code path), and avoiding an unnecessary copy in the common code path for a moderately common operation (passing **kwargs and no other keyword arguments) seems valuable, so I still think it's worth the change.

    If this were back in the pre-3.8 timeframe, I'd be more leery of making the change, because vectorcall was used far less frequently (and wasn't even officially documented for third-party packages, so they couldn't use it), but at this point (with so much of the built-ins and standard library converted to Argument Clinic and therefore vectorcall automatically, and all user-defined functions being vectorcall, and third-party libraries have had several years to adopt vectorcall), the vast majority of calls will not pay the single cost this change imposes, and it undoes a performance regression from 3.8->3.9 as a side-benefit (without undoing the safety features that causes that regression). The tests I added will protect against future optimizations inadvertently reintroducing the edge case that made 3.8 technically incorrect to boot.

  3. added
    performance
    3.11
    and removed
    3.9 (EOL)
    on May 3, 2022
  4. added
    interpreter-core
    on May 3, 2022
  5. added
    3.12
    and removed
    3.11
    on Sep 11, 2022
  6. added 8 commits that reference this issue on Aug 24, 2026
  7. added 2 commits that reference this issue on Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.12interpreter-coreperformance

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions