[issue29737] Optimize concatenating empty tuples

2017-03-25 Thread STINNER Victor

STINNER Victor added the comment:

I like the change. It prevents to duplicate tuples and so reduce the memory
footprint. PGO compilation helps branch prediction anyway.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29737] Optimize concatenating empty tuples

2017-03-25 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

The PR already was merged when you wrote your comment Raymond. If you insist I 
can revert it. But 0f7b0b397e12514ee213bc727c9939b66585cbe2 depends on it.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29737] Optimize concatenating empty tuples

2017-03-24 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29737] Optimize concatenating empty tuples

2017-03-24 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:


New changeset 98e80c2babac0003182c3482c6c5437ea111e795 by Serhiy Storchaka in 
branch 'master':
bpo-29737: Optimize concatenating with empty tuple. (#524)
https://github.com/python/cpython/commit/98e80c2babac0003182c3482c6c5437ea111e795


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29737] Optimize concatenating empty tuples

2017-03-06 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

I agree with your comments Raymond, but let me to expose my reasons.

An idea of optimizing empty tuple concatenating is inspired by partial(). It 
concatenates two tuples of arguments and it is common when one of tuple is 
empty. Current C implementation makes special case for this (and does this 
suboptimal). With optimized empty tuple concatenating it could be simpler and 
more efficient. Even when C implementation of partial() will not use this 
feature (see issue29735), I hope it can help in Python implementation of 
partial() and other partial-like functions.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29737] Optimize concatenating empty tuples

2017-03-06 Thread Raymond Hettinger

Raymond Hettinger added the comment:

Is it at all common to concatenate empty tuples?  This seems like optimizing 
something that rarely occurs.

Also, the timings can be misleading if in real code these changes cause new 
branch mispredictions here which can slow the common case.  See 
http://stackoverflow.com/questions/11227809

--
nosy: +rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29737] Optimize concatenating empty tuples

2017-03-06 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
pull_requests: +432

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29737] Optimize concatenating empty tuples

2017-03-06 Thread Serhiy Storchaka

New submission from Serhiy Storchaka:

Since tuples are immutable, concatenating with empty tuple can be optimized by 
returning an opposite argument.

Microbenchmarks (the difference is larger for larger tuples):

$ ./python -m perf timeit --duplicate=100 -s 'a = (1, 2)' 'a + ()'
Unpatched:  Median +- std dev: 288 ns +- 12 ns
Patched:Median +- std dev: 128 ns +- 5 ns

$ ./python -m perf timeit --duplicate=100 -s 'a = (1, 2)' '() + a'
Unpatched:  Median +- std dev: 285 ns +- 16 ns
Patched:Median +- std dev: 128 ns +- 6 ns

Non-empty tuples are not affected:

$ ./python -m perf timeit --duplicate=100 -s 'a = (1, 2)' 'a + a'
Unpatched:  Median +- std dev: 321 ns +- 24 ns
Patched:Median +- std dev: 317 ns +- 26 ns

--
components: Interpreter Core
messages: 289129
nosy: haypo, serhiy.storchaka
priority: normal
severity: normal
stage: patch review
status: open
title: Optimize concatenating empty tuples
type: performance
versions: Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com