Author serhiy.storchaka
Recipients serhiy.storchaka, vstinner
Date 2017-03-06.19:48:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1488829716.87.0.539974742004.issue29737@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2017-03-06 19:48:36serhiy.storchakasetrecipients: + serhiy.storchaka, vstinner
2017-03-06 19:48:36serhiy.storchakasetmessageid: <1488829716.87.0.539974742004.issue29737@psf.upfronthosting.co.za>
2017-03-06 19:48:36serhiy.storchakalinkissue29737 messages
2017-03-06 19:48:36serhiy.storchakacreate