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 <
[email protected]> 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 is being created at that
point, so the interpreter can know there isn't anything referencing it
anywhere else.

-CHB


> 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 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 useful
>> case, the refcount threshold needs to be set higher than
>> 1.
>>
>> Some experiments I did suggest that if you set it high
>> enough for x += y to trigger it, then it will also be
>> triggered in Joe's case.
>>
>> BTW, isn't there already a similar optimisation somewhere
>> for concatenating strings? Does it still exist? How does
>> it avoid this issue?
>>
>> --
>> Greg
>>
>> ___
>> Python-Dev mailing list
>> [email protected]
>> https://mail.python.org/mailman/listinfo/python-dev
>> Unsubscribe: https://mail.python.org/mailman/options/python-dev/joe%40qua
>> ntopian.com
>>
>
>
> ___
> Python-Dev mailing list
> [email protected]
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: https://mail.python.org/mailman/options/python-dev/
> chris.barker%40noaa.gov
>
>


-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R(206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115   (206) 526-6317   main reception

[email protected]
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


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 <
> [email protected]> 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 is being created at that
> point, so the interpreter can know there isn't anything referencing it
> anywhere else.

You can go to the source and check yourself:
https://github.com/python/cpython/blob/master/Python/ceval.c#L5226-L5277

Regards

Antoine.


___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com