Change METH_VARARGS
to METH_O
; much faster parsing 🎉😅
#130
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.
What are you trying to accomplish?
When I saw that cPython's 3.11
datetime.fromisoformat
was outperformingciso8601.parse_datetime
(without time zone information), I went looking to see what they were doing differently.Their methods were defined as
METH_O
(i.e., method with single positional parameter), while ours were usingMETH_VARARGS
(i.e., method with multiple positional parameters). It turns out there is a large performance benefit when you:a) No longer have to call
PyArg_ParseTuple
b) Allow Python to optimize based on knowing there is just a single parameter
What approach did you choose and why?
I changed each of the parser methods from
METH_VARGS
toMETH_O
.This changed their C signatures, and so I had to plumb through the changes.
What should reviewers focus on?
...
The impact of these changes
Embarrassingly faster parsing times:
ciso8601 (this PR)
datetime.fromisoformat
ciso8601 v2.2.0