Skip to content

bpo-36904: Optimize _PyStack_UnpackDict #14517

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

Merged
merged 1 commit into from
Jul 2, 2019
Merged

Conversation

jdemeyer
Copy link
Contributor

@jdemeyer jdemeyer commented Jul 1, 2019

Optimize, clean up and fix _PyStack_UnpackDict:

  1. _PyStack_UnpackDict is made a static function inside call.c.
  2. The API is simplified: the new argument vector is returned directly instead of being passed via a pointer.
  3. Move the case of no keywords outside of _PyStack_UnpackDict, so _PyStack_UnpackDict is now only used when there actually are keyword arguments. This speeds up the case of no keywords and it simplifies the code.
  4. Allocate the argument vector such that it supports PY_VECTORCALL_ARGUMENTS_OFFSET. Tests indicate that _PyStack_UnpackDict is responsible for about 60% of cases where method_vectorcall needs to do an allocation. With this change, these allocations are no longer needed.
  5. Move the freeing code (which is not trivial) to a new function _PyStack_UnpackDict_Free.
  6. Fix the overflow check by using Py_ssize_t instead of size_t. In the old code, the overflow check could theoretically overflow (the right hand side could be negative).

CC @encukou @methane

https://bugs.python.org/issue36904

@mangrisano
Copy link
Contributor

/cc @vstinner

@methane methane merged commit d4efd91 into python:master Jul 2, 2019
@jdemeyer
Copy link
Contributor Author

jdemeyer commented Jul 2, 2019

Thank you!

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.

5 participants