-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
Restore (or beat) Python 2 performance for arithmetic operations on ints that fit into a single word #101291
Comments
…r and PyLongValue struct. (pythonGH-101292)
* Eliminate all remaining uses of Py_SIZE and Py_SET_SIZE on PyLongObject, adding asserts. * Change layout of size/sign bits in longobject to support future addition of immortal ints and tagged medium ints. * Add functions to hide some internals of long object, and for setting sign and digit count. * Replace uses of IS_MEDIUM_VALUE macro with _PyLong_IsCompact().
…2464) * Eliminate all remaining uses of Py_SIZE and Py_SET_SIZE on PyLongObject, adding asserts. * Change layout of size/sign bits in longobject to support future addition of immortal ints and tagged medium ints. * Add functions to hide some internals of long object, and for setting sign and digit count. * Replace uses of IS_MEDIUM_VALUE macro with _PyLong_IsCompact().
…2464) * Eliminate all remaining uses of Py_SIZE and Py_SET_SIZE on PyLongObject, adding asserts. * Change layout of size/sign bits in longobject to support future addition of immortal ints and tagged medium ints. * Add functions to hide some internals of long object, and for setting sign and digit count. * Replace uses of IS_MEDIUM_VALUE macro with _PyLong_IsCompact().
Co-authored-by: Petr Viktorin <encukou@gmail.com>
…pythonGH-104742) (cherry picked from commit e295d86) Co-authored-by: Mark Shannon <mark@hotpy.org>
Has there been any progress in documenting the changes made in Python 3.12? (#101292 (comment)) |
Maybe @markshannon can answer that? AFAICT all the commits linked above are his. I know we had someone who was interested in pursuing this further but she had to bow out. |
@markshannon Where are we with documentation for this? If it's not documented, do we need to start working to roll this back? I'm not comfortable with this change in rc1 if it's not documented. |
Mark is at EuroPython. If you are there too you can talk to him. We will get it documented. |
I did a little research. It looks like there are two key changes. First,
I.e., there was an array The new (still internal) representation is as follows:
and there are new internal macros to determine the number of digits and the sign, and a bunch of internal macros to handle "compact" values (which fit in 1-2 "digits"). There are two new public, unstable APIs to support the concept of "compact" values: Details of what the bits in I think in the What's New in 3.12 we should at least mention the change in the struct (calling out that using @Yhg1s @markshannon What do you think of this? I volunteer to make a PR for what's new 3.12 along the lines of what I wrote above. |
…rnals have changed. (pythonGH-107388) (cherry picked from commit 1ee605c) Co-authored-by: Mark Shannon <mark@hotpy.org>
@Yhg1s Assuming the changes Mark made to what's new in 3.12 are what you wanted? |
Yep, that's adequate. |
…ythonGH-125384) (cherry picked from commit c6d7b64) Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
…ythonGH-125384) (cherry picked from commit c6d7b64) Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
In Python 2
int
s andlong
s were different objects, and the design of each was tailored to the different size and use cases.In Python3 we dropped the distinction, but we also dropped the design for
int
s that fit into a single word.We have added various fast paths for "medium" integers (e.g. #89109) but the underlying data structure gets in the way.
We should layout the int/long object so that it supports fast operations for most integers.
See faster-cpython/ideas#548 for a fuller discussion
Linked PRs
PyLongObject
struct #101292PyLongObject
internals have changed. #107388PyLongObject
internals have changed. (GH-107388) #107392The text was updated successfully, but these errors were encountered: