Message215192
> 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. |
|
Date |
User |
Action |
Args |
2014-03-30 18:23:06 | rhettinger | set | recipients:
+ rhettinger, pitrou, alex, serhiy.storchaka |
2014-03-30 18:23:06 | rhettinger | set | messageid: <1396203786.01.0.00922006685472.issue21101@psf.upfronthosting.co.za> |
2014-03-30 18:23:05 | rhettinger | link | issue21101 messages |
2014-03-30 18:23:05 | rhettinger | create | |
|