Re: [Python-Dev] Inplace operations for PyLong objects

2017-09-02 Thread Antoine Pitrou
On Sat, 2 Sep 2017 10:38:05 -0700 Chris Barker wrote: > On Fri, Sep 1, 2017 at 6:16 PM, Joe Jevnik via Python-Dev < > python-dev@python.org> wrote: > > > The string concat optimization happens in the interpreter dispatch for > > INPLACE_ADD > > > > In that case, isn't

Re: [Python-Dev] Inplace operations for PyLong objects

2017-09-02 Thread Chris Barker
On Fri, Sep 1, 2017 at 6:16 PM, Joe Jevnik via Python-Dev < python-dev@python.org> wrote: > The string concat optimization happens in the interpreter dispatch for > INPLACE_ADD > In that case, isn't there a new string being build, all in one line of python? that is, the string the optimization

Re: [Python-Dev] Inplace operations for PyLong objects

2017-09-01 Thread Joe Jevnik via Python-Dev
The string concat optimization happens in the interpreter dispatch for INPLACE_ADD On Fri, Sep 1, 2017 at 9:10 PM, Greg Ewing wrote: > Chris Angelico wrote: > >> This particular example is safe, because the arguments get passed >> individually - so 'args' has one

Re: [Python-Dev] Inplace operations for PyLong objects

2017-09-01 Thread Greg Ewing
Chris Angelico wrote: This particular example is safe, because the arguments get passed individually - so 'args' has one reference, plus there's one more for the actual function call However, that's also true when you use the += operator, so if the optimisation is to trigger at all in any

Re: [Python-Dev] Inplace operations for PyLong objects

2017-09-01 Thread Chris Angelico
On Sat, Sep 2, 2017 at 6:35 AM, Joe Jevnik via Python-Dev wrote: > Is it true that checking for refcount == 1 is enough? What if a user wrote: > > args = (compute_integer(), 5) > # give away args to someone > int.__iadd__(*args) > > here `args[0]` still has refcount=1

Re: [Python-Dev] Inplace operations for PyLong objects

2017-09-01 Thread Manciu, Catalin Gabriel
> My question is -- how can the interpreter know if it can alter what is > supposed to be an immutable in-place? If it's used only internally to a > function, the it would be safe, but how to know that? > -CHB You can just check the reference count of your object, it's a member of the

Re: [Python-Dev] Inplace operations for PyLong objects

2017-09-01 Thread Joe Jevnik via Python-Dev
Is it true that checking for refcount == 1 is enough? What if a user wrote: args = (compute_integer(), 5) # give away args to someone int.__iadd__(*args) here `args[0]` still has refcount=1 because only `args` owns this integer. On Fri, Sep 1, 2017 at 4:19 PM, Jelle Zijlstra

Re: [Python-Dev] Inplace operations for PyLong objects

2017-09-01 Thread Jelle Zijlstra
2017-09-01 13:05 GMT-07:00 Chris Barker : > On Thu, Aug 31, 2017 at 5:12 PM, Antoine Pitrou > wrote: > >> I'm skeptical there are some programs out there that are limited by the >> speed of PyLong inplace additions. >> > > indeed, but that could be

Re: [Python-Dev] Inplace operations for PyLong objects

2017-09-01 Thread Chris Barker
On Thu, Aug 31, 2017 at 5:12 PM, Antoine Pitrou wrote: > I'm skeptical there are some programs out there that are limited by the > speed of PyLong inplace additions. > indeed, but that could be said about any number of operations. My question is -- how can the interpreter

Re: [Python-Dev] Inplace operations for PyLong objects

2017-08-31 Thread Antoine Pitrou
On Thu, 31 Aug 2017 23:35:34 + "Manciu, Catalin Gabriel" 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

Re: [Python-Dev] Inplace operations for PyLong objects

2017-08-31 Thread Chris Angelico
On Fri, Sep 1, 2017 at 9:35 AM, Manciu, Catalin Gabriel wrote: > 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

Re: [Python-Dev] Inplace operations for PyLong objects

2017-08-31 Thread Manciu, Catalin Gabriel
>On my machine, the more realistic code, with an implicit C loop, >the_value = sum(the_increment for i in range(total_iters)) >gives the same value twice as fast as your explicit Python loop. >(I cut total_iters down to 10**7). Your code is faster due to a number of reasons: - range in Python

Re: [Python-Dev] Inplace operations for PyLong objects

2017-08-31 Thread Terry Reedy
On 8/31/2017 2:40 PM, Manciu, Catalin Gabriel wrote: Hi everyone, While looking over the PyLong source code in Objects/longobject.c I came across the fact that the PyLong object doesnt't include implementation for basic inplace operations such as adding or multiplication: [...] long_long,

[Python-Dev] Inplace operations for PyLong objects

2017-08-31 Thread Manciu, Catalin Gabriel
Hi everyone, While looking over the PyLong source code in Objects/longobject.c I came across the fact that the PyLong object doesnt't include implementation for basic inplace operations such as adding or multiplication: [...] long_long, /*nb_int*/ 0,