[Python-Dev] 30-bit PyLong digits in 3.1?

Mark Dickinson dickinsm at gmail.com
Tue Feb 17 19:38:04 CET 2009


A few months ago there was a discussion [1] about changing
Python's long integer type to use base 2**30 instead of base
2**15.  http://bugs.python.org/issue4258 was opened for this.

With much help from many people (but especially Antoine
and Victor), I've finally managed to put together an
essentially finished patch for this (see 30bit_longdigit14.patch
in the tracker).

I'd like to get this in for 3.1. Any objections or comments?
Is this PEP territory?

Summary of the patch:

* Apart from improved performance, the effects should be
  almost entirely invisible to users.

* By default, 30-bit digits are used only when both 32-bit
  and 64-bit integer types are available; otherwise the
  code falls back to the usual 15-bit digits.  For Unix, there's
  a configure option --enable-big-digits that overrides this
  default.  In particular, you can use --disable-big-digits
  to force 15-bit digit longs.

* There's a new structseq sys.int_info that looks like this:

    >>> sys.int_info
    sys.int_info(bits_per_digit=30, sizeof_digit=4)

  the sizeof_digit is mostly there to help out the sys.getsizeof
  tests in test_sys.

* Benchmarks show significant speedups (20% and more)
  for integer arithmetic
  on 64-bit systems, and lesser speedups on 32-bit systems.
  Operations with single-digit integers aren't affected much
  either way;  most of the benefit seems to be for operations
  with small multi-digit integers.

* There are more performance improvements planned (see
   the issue discussion for details);  I left them out of the
   current patch for simplicity, and because they still need
   proper testing and benchmarking.

Mark

[1] http://mail.python.org/pipermail/python-dev/2008-November/083315.html


More information about the Python-Dev mailing list