[Python-Dev] Changing python int to "long long".
jafo-python-dev at tummy.com
Tue May 23 13:08:06 CEST 2006
We've been discussing the possibility of converting the Python int type to
long long (from long). I played around with it some, and it's going to be
a huge change that probably will break most C extensions until. However,
as uncletimmy says, "Python is so stinking slow" that it probably won't
make much of a negative impact on the performance.
The reason we're looking at this at Need for Speed is that EWT has a lot of
code that uses ints between the 32 and 64 bit range. It'd be a hard change
to make to convert to long long for regular ints. I'm going to speak with
John and Runar today about if we can make just a long long extension type
and live with it not integrating with other type coercion as well as an int
The big deal right now is on 32 bit platforms, giving the 64-bits for int.
However, it will also be a win for 64-bit platforms for ints that fall
between 64 and 128 bits.
So, I ran pybench on a half-arsed conversion of ints to long long, and only
lost around 1.11% over all. However, for simple math I got a solid 25%
speed-up (n = ((((i << 33) * 2) + 1) / 3) - 2), and for 1<<35 I got a 34%
speed up, compared with them getting converted to Python longs.
For ints that will fit entirely within 32-bits, I'm seeing around 11% worse
performance when going to 64-bit types.
This is all on the 2.5 trunk.
My conclusion is that it's probably enough of a performance drop that we
can't just do it wholesale. It has a big gain for ints within 32 and 64
on 32-bit platforms, but for <32-bit ints it's going to be pretty bad.
Within the next few years many platforms, particularly performance-critical
ones, will probably be 64 bit anyway, so fewer people will probably be able
to see an advantage to it.
The ideal would probably be to have another int type and up-convert to a
long long, THEN go to arbitrary precision, but that's a pretty big change.
Less big than converting the int to long long though. The easiest would be
to make an extension that has long long, if that will work for speeding up
applications like EWT has. I'll follow up with them on this.
Any thoughts on this?
Linux: When you need to run like a greased weasel.
-- Sean Reifschneider, 1998
Sean Reifschneider, Member of Technical Staff <jafo at tummy.com>
tummy.com, ltd. - Linux Consulting since 1995: Ask me about High Availability
More information about the Python-Dev