Raymond Hettinger added the comment:

> 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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue21101>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to