-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-37207: Use vertorcall for list() #18928
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just left nit comment, else LGTM
Misc/NEWS.d/next/Core and Builtins/2019-06-09-10-54-31.bpo-37207.bLjgLS.rst
Outdated
Show resolved
Hide resolved
Co-Authored-By: Dong-hee Na <donghee.na92@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I re-left the comment for this issue.
Objects/listobject.c
Outdated
list_vectorcall(PyObject *type, PyObject * const*args, | ||
size_t nargsf, PyObject *kwnames) | ||
{ | ||
if (kwnames && PyTuple_GET_SIZE(kwnames) != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since #18980 is merged.
We can replace the logic into
if (!_PyArg_NoKwnames("list", kwnames)) {
return NULL;
}
Objects/listobject.c
Outdated
return NULL; | ||
} | ||
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); | ||
if (nargs > 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can replace it into
if (!_PyArg_CheckPositional("list", nargs, 0, 1)) {
return NULL;
}
return NULL; | ||
} | ||
|
||
assert(PyType_Check(type)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this assert into the top of the function body since this parameter is the 1st parameter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why that's necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the change :)
lgtm
@corona10 @encukou: Can one of you please run a benchmark? @markshannon wrote "As an initial step, we can speed up calls to range, list and dict by about 30%." at https://bugs.python.org/issue37207#msg345077 but I would prefer to see directly results of a microbenchmarks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. But it would be better if someone can benchmark this optimization ;-)
@vstinner
It shows a similar enhancement to the collections to which this feature is applied. |
Ok, 1.15x faster (-13%) and -118 nanoseconds looks worth it to me. list(iterable) is commonly used. Again, LGTM ;-) |
I merged the PR, thanks @markshannon, @encukou and @corona10 ;-) There was an interesting typo: "vertorcall call" :-) |
This continues the
list()
part of #13930. The complete pull request is stalled on discussions around dicts, butlist()
should not be controversial. (Range was done in #18464 and I plan to open PRs for other parts if this is merged.)I did two small changes on top of Mark's code.
https://bugs.python.org/issue37207