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-42064: Offset arguments for PyObject_Vectorcall in the _sqlite module #27931

Merged
merged 3 commits into from
Aug 31, 2021

Conversation

encukou
Copy link
Member

@encukou encukou commented Aug 24, 2021

This weird mechanism allows e.g. methods to be called efficiently by providing space for a "self" argument; see PY_VECTORCALL_ARGUMENTS_OFFSET docs.

https://bugs.python.org/issue42064

This allows e.g. methods to be called efficiently by providing
space for a "self" argument; see PY_VECTORCALL_ARGUMENTS_OFFSET docs.
@corona10
Copy link
Member

Out of curiosity, How efficient? is there any benchmark?

@encukou
Copy link
Member Author

encukou commented Aug 24, 2021

Out of curiosity, How efficient? is there any benchmark?

I'm not aware of one, but the docs say this is encouraged :)

@erlend-aasland
Copy link
Contributor

erlend-aasland commented Aug 24, 2021

LGTM, thanks for spotting this! This makes sense for the collation callback, but I can't see how the calls in new_statement_cache and get_statement_from_cache will benefit from this. OTOH, it won't hurt to use the encouraged calling convention :)

Comment on lines 67 to 68
PyObject *inner = PyObject_Vectorcall(
lru_cache, args + 1, 1 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please break lines according to PEP 7? I'm striving to keep all sqlite3 changes PEP 7 compliant :)
Ditto for the other calls.

Copy link
Contributor

Choose a reason for hiding this comment

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

That is, either:

Suggested change
PyObject *inner = PyObject_Vectorcall(
lru_cache, args + 1, 1 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
PyObject *inner = PyObject_Vectorcall(lru_cache, args + 1,
1 | PY_VECTORCALL_ARGUMENTS_OFFSET,
NULL);

or:

Suggested change
PyObject *inner = PyObject_Vectorcall(
lru_cache, args + 1, 1 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
size_t nargs = 1 | PY_VECTORCALL_ARGUMENTS_OFFSET;
PyObject *inner = PyObject_Vectorcall(lru_cache, args + 1, nargs, NULL);

@encukou encukou merged commit 01dea5f into python:main Aug 31, 2021
@encukou encukou deleted the sqlite-vectorcall-offset branch August 31, 2021 12:34
@encukou
Copy link
Member Author

encukou commented Aug 31, 2021

Thanks for the reviews!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants