You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Seemingly unnecessary complexification of foo(**kw) #86199
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.
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.
Activity
markshannon commentedon May 3, 2022
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.
MojoVampire commentedon May 3, 2022
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
**kwargsto forward on to an internal call, e.g. in an overridden method like__init__in inheritance hierarchies that accepts and forward s**kwargsto 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_Callseems 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**kwargsand 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.
pythongh-86199: Simplify by adopting the pythonGH-92192 approach
pythongh-86199: Use PyDict_Copy instead of a copy helper
pythongh-86199: Enter recursive call before copying kwargs; trim comm…
pythongh-86199: Lock the kwargs dict in _PyStack_UnpackDict
pythongh-86199: Add free-threading regression test for f(**kwargs) calls
pythongh-86199: Target the C-API unpack path in the FT regression test
pythongh-86199: Rename the FT kwargs test and tighten its names
pythongh-86199: Avoid an unnecessary dict copy for f(**kwargs) calls
pythongh-86199: Fix CI: move kwargs conversion out of the instruction…
pythongh-86199: Keep &dupkey out of DICT_MERGE too (MSVC tail-call bu…
Merge remote-tracking branch 'origin/main' into pythongh-86199-kwargs…