Skip to content
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

Merged
merged 7 commits into from
Mar 30, 2020
Merged

Conversation

encukou
Copy link
Member

@encukou encukou commented Mar 11, 2020

This continues the list() part of #13930. The complete pull request is stalled on discussions around dicts, but list() 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

Copy link
Member

@corona10 corona10 left a 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

Co-Authored-By: Dong-hee Na <donghee.na92@gmail.com>
Copy link
Member

@corona10 corona10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@encukou

Hi, I re-left the comment for this issue.

list_vectorcall(PyObject *type, PyObject * const*args,
size_t nargsf, PyObject *kwnames)
{
if (kwnames && PyTuple_GET_SIZE(kwnames) != 0) {
Copy link
Member

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;
}

return NULL;
}
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
if (nargs > 1) {
Copy link
Member

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));
Copy link
Member

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?

Copy link
Member Author

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.

@corona10 corona10 requested a review from vstinner March 17, 2020 09:39
Copy link
Member

@corona10 corona10 left a 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

@vstinner
Copy link
Member

@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.

Copy link
Member

@vstinner vstinner left a 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 ;-)

@corona10
Copy link
Member

@vstinner
When testing with list((1, 2, 3, 4, 5)) the performance enhancement shown like this.

Mean +- std dev: [master] 909 ns +- 29 ns -> [pr-18927] 791 ns +- 43 ns: 1.15x faster (-13%)

It shows a similar enhancement to the collections to which this feature is applied.

@vstinner
Copy link
Member

Ok, 1.15x faster (-13%) and -118 nanoseconds looks worth it to me. list(iterable) is commonly used.

Again, LGTM ;-)

@vstinner vstinner merged commit ce10554 into python:master Mar 30, 2020
@vstinner
Copy link
Member

I merged the PR, thanks @markshannon, @encukou and @corona10 ;-) There was an interesting typo: "vertorcall call" :-)

@encukou encukou deleted the vertorcall-newlist branch March 31, 2020 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants