You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Integer operations are inefficient for "medium" integers. #89109
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2021-08-26.15:09:37.280>created_at=<Date2021-08-18.10:25:32.126>labels= ['interpreter-core', 'performance']
title='Integer operations are inefficient for "medium" integers.'updated_at=<Date2021-12-11.04:39:53.226>user='https://github.com/markshannon'
"Medium" integers are those with a single internal digit or zero.
Medium integers are integers in the range -2**30 to +2**30 on 64 bit machines.
"Small" integers, -5 to 256 are cached, but are represented as medium integers internally.
To a good approximation, all integers are "medium".
However, we make little effort to exploit that fact in the code for binary operations, which are very common operations on integers.
There are still various minor inefficiencies in testing to see whether an int is a medium value, and then throwing away size information before creating result objects.
I'm not expecting this to make much difference, but every little helps.
New changeset 15d50d7 by Mark Shannon in branch 'main': bpo-44946: Streamline operators and creation of ints for common case of single 'digit'. (GH-27832) 15d50d7
Activity
markshannon commentedon Aug 18, 2021
"Medium" integers are those with a single internal digit or zero.
Medium integers are integers in the range -2**30 to +2**30 on 64 bit machines.
"Small" integers, -5 to 256 are cached, but are represented as medium integers internally.
To a good approximation, all integers are "medium".
However, we make little effort to exploit that fact in the code for binary operations, which are very common operations on integers.
mdickinson commentedon Aug 18, 2021
We already special-case medium integers in the Objects/longobject.c code, in various places. For example for addition, here:
cpython/Objects/longobject.c
Lines 3070 to 3072 in 3240bc6
Are you proposing further changes in longobject.c, or some other mechanism?
mdickinson commentedon Aug 18, 2021
See also bpo-21955, bpo-10044, and
cpython/Python/ceval.c
Lines 1986 to 1991 in 3240bc6
markshannon commentedon Aug 18, 2021
Just changes to longobject.c.
There are still various minor inefficiencies in testing to see whether an int is a medium value, and then throwing away size information before creating result objects.
I'm not expecting this to make much difference, but every little helps.
markshannon commentedon Aug 25, 2021
New changeset 15d50d7 by Mark Shannon in branch 'main':
bpo-44946: Streamline operators and creation of ints for common case of single 'digit'. (GH-27832)
15d50d7