This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients alex, pitrou, rhettinger, serhiy.storchaka
Date 2014-03-30.18:23:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1396203786.01.0.00922006685472.issue21101@psf.upfronthosting.co.za>
In-reply-to
Content
> Would it be reasonable to develop a Python API for this? 

I suspect that in pure Python, the overhead would exceed the benefit.

Current code:

   d[key] = d[key] + 1

Effort to save a double hash:

   h = hash(key)
   c = d.getitem_known_hash(key, hash)
   d.setitem_known_hash(key, hash, c + 1)

In PyPy, the second code sample might actually be faster that the first, but all the other pythons suffer from interpreter overhead, a double dict lookup for the hash() function, two dict lookups just to find the new methods, allocating a bound method, and forming two argument tuples.

There is also an API design issue.  The pure python core datatype APIs are designed in a way to encourage higher level thinking (that is why we can't directly manage hash table sparsity or list over-allocation for example).

In contrast, the C API is aimed at users who seek additional control and  optimization at a lower level than the core language provides.  We tend to expose a number of tools at the C level that would be inappropriate for higher-level code.
History
Date User Action Args
2014-03-30 18:23:06rhettingersetrecipients: + rhettinger, pitrou, alex, serhiy.storchaka
2014-03-30 18:23:06rhettingersetmessageid: <1396203786.01.0.00922006685472.issue21101@psf.upfronthosting.co.za>
2014-03-30 18:23:05rhettingerlinkissue21101 messages
2014-03-30 18:23:05rhettingercreate