[New-bugs-announce] [issue9778] Make hash values the same width as a pointer (or Py_ssize_t)

Antoine Pitrou report at bugs.python.org
Sun Sep 5 00:11:31 CEST 2010

New submission from Antoine Pitrou <pitrou at free.fr>:

Currently, Python produces hash values with fit in a C "long". This is fine at first sight, but in the context of dict and set implementations, it means that
1) holding hashes and indices in the same field of a structure requires some care (see issue1646068)
2) on platforms where a long is smaller than a Py_ssize_t (e.g. Win64), very big hash tables could suffer from lots of artificial collisions (the hash table being bigger than the range of possible hash values)
3) when a long is smaller than Py_ssize_t, we don't save any size anyway, since having some pointers follow a C "long" in a structure implies some padding to keep all fields naturally aligned

A future-proof option would be to change all hash values to be of Py_ssize_t values rather than C longs. Either directly, or by defining a new dedicated alias Py_hash_t. This would also impact the ABI, I suppose.

components: Interpreter Core
messages: 115617
nosy: belopolsky, georg.brandl, jimjjewett, ked-tao, loewis, mark.dickinson, pitrou, rhettinger, tim_one
priority: normal
severity: normal
status: open
title: Make hash values the same width as a pointer (or Py_ssize_t)
type: feature request
versions: Python 3.2, Python 3.3

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list