[Python-Dev] Inplace operations for PyLong objects (original) (raw)

Antoine Pitrou solipsis at pitrou.net
Thu Aug 31 20:12:59 EDT 2017


On Thu, 31 Aug 2017 23:35:34 +0000 "Manciu, Catalin Gabriel" <catalin.gabriel.manciu at intel.com> wrote:

The focus of this experiment was inplace adds in general. While, as you've shown, there are ways to write the loop optimally, the benchmark was written as a huge loop just to showcase that there is an improvement using this approach. The performance improvement is a result of not having to allocate/deallocate a PyLong per iteration. A huge Python program with lots of PyLong inplace operations (not just adds, this can be applied to all PyLong inplace operations), regardless of them being in a loop or not, might benefit from such an optimization.

I'm skeptical there are some programs out there that are limited by the speed of PyLong inplace additions. Even if you have a bigint-intensive workload (say public-key cryptography, not that it's specifically a good idea to do so in pure Python), chances are it's spending much of its time in more sophisticated operations such as multiplication, power or division.

In other words, while your experiment has intellectual and educational interest, I don't think it shows the path to a useful optimization.

Regards

Antoine.



More information about the Python-Dev mailing list