Repository navigation
Conversation
`@vectorcall` with `**kwargs` always delegated to the keyword helper, which only reads a kwargs dict, so it couldn't be generated. The vectorcall now parses positionals with the shared positional emitter and builds the dict from kwnames only when there are keywords, otherwise passing NULL, as the tuple parser does. The `*args` and `**kwargs` parsers take the calling convention explicitly rather than reading `self.fastcall`, which describes the Python-visible entry point having stack style args, not the vectorcall. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ree.Element
xml.etree.ElementTree.Element gains a generated vectorcall. Keys that
are not strings in `**extra` now raise TypeError on a normal call, as
the Python implementation already did, because vectorcall keywords must
be strings; an explicit `__init__` call and subclasses still accept them.
`@text_signature` keeps the documented `(tag, /, attrib={}, **extra)`:
`attrib` can still be passed by keyword, which the impl pops from `extra`.
Merging the keywords into the attributes now copies them with
PyDict_Copy() instead of PyDict_New() plus PyDict_Update(), and pops
`attrib` with `_Py_ID(attrib)` rather than creating a string per call;
SubElement shares that helper.
pyperf microbenchmark (PGO+LTO, run serially):
| Benchmark | base | Element |
|------------------------|:-------:|:---------------------:|
| E('a', x='1') | 116 ns | 76.3 ns: 1.52x faster |
| E('a') | 42.6 ns | 28.2 ns: 1.51x faster |
| E('a', attrib=d) | 122 ns | 82.8 ns: 1.47x faster |
| E('a', d) | 73.8 ns | 53.6 ns: 1.38x faster |
| SE(E('p'), 'a', x='1') | 161 ns | 120 ns: 1.35x faster |
| E('a', d, y='2') | 102 ns | 80.3 ns: 1.27x faster |
| S('a') | 49.4 ns | 39.8 ns: 1.24x faster |
Benchmark code:
```python
import pyperf
runner = pyperf.Runner()
setup = ("from _elementtree import Element as E, SubElement as SE\n"
"d = {'x': '1'}\n"
"class S(E): pass")
for stmt in ["E('a')", "E('a', d)", "E('a', x='1')", "E('a', d, y='2')",
"E('a', attrib=d)", "S('a')", "SE(E('p'), 'a', x='1')"]:
runner.timeit(stmt, stmt, setup)
```
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eywords Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add working code generation for
@vectorcallwith**kwargs. The first commit adds support to libclinic converters to get keyword args from stack form rather than a dict. When there are no keyword arguments avoid creating a dictionary.Exercise that code generation with
xml.etree.ElementTree.Element. This adds a small behavior change in that non-string keyword arguments will raiseTypeErrorrather than succeeding. Such keys can still be passed in usingattrib.@text_signaturekeeps the documented(tag, /, attrib={}, **extra):attribcan still be passed by keyword, which the impl pops fromextra.Merging the keywords into the attributes now copies them with
PyDict_Copy()instead ofPyDict_New()plusPyDict_Update(), and popsattribwith_Py_ID(attrib)rather than creating a string per call;SubElementshares that helper.pyperf microbenchmark (PGO+LTO, run serially):
Benchmark code: