This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients Demur Rumed, Mark.Shannon, benjamin.peterson, christian.heimes, mark.dickinson, nascheme, ncoghlan, pitrou, rhettinger, serhiy.storchaka, trent
Date 2017-12-28.19:39:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1514489961.2.0.213398074469.issue17611@psf.upfronthosting.co.za>
In-reply-to
Content
Results of microbenchmarks:

$ ./python -m perf timeit -s 'a = list(range(1000))' -- 'for i in a: pass'
Mean +- std dev: 6.31 us +- 0.09 us

$ ./python -m perf timeit -s 'a = list(range(1000))' -- '
for i in a:
    try: pass
    finally: pass
'
Unpatched:  Mean +- std dev: 16.3 us +- 0.2 us
PR 2827:    Mean +- std dev: 16.2 us +- 0.2 us
PR 4682:    Mean +- std dev: 16.2 us +- 0.2 us
PR 5006:    Mean +- std dev: 14.5 us +- 0.4 us

$ ./python -m perf timeit -s 'a = list(range(1000))' -- '
for i in a:
    try: continue
    finally: pass
'
Unpatched:  Mean +- std dev: 24.0 us +- 0.5 us
PR 2827:    Mean +- std dev: 11.9 us +- 0.1 us
PR 4682:    Mean +- std dev: 12.0 us +- 0.1 us
PR 5006:    Mean +- std dev: 19.0 us +- 0.3 us

$ ./python -m perf timeit -s 'a = list(range(1000))' -- '
for i in a:
    while True:
        try: break
        finally: pass
'
Unpatched:  Mean +- std dev: 25.9 us +- 0.5 us
PR 2827:    Mean +- std dev: 11.9 us +- 0.1 us
PR 4682:    Mean +- std dev: 12.0 us +- 0.1 us
PR 5006:    Mean +- std dev: 18.9 us +- 0.1 us


PR 2827 and PR 4682 have the same performance. The overhead of the finally block is smaller in PR 5006, perhaps because BEGIN_FINALLY pushes 1 NULL instead of 6 NULLs. CALL_FINALLY adds 4.5 ns in the latter too examples. This overhead could be decreased by using special cache for Python integers that represent return addresses or using separate stack for return addresses. But this looks as an overkill to me now. 4.5 ns is pretty small overhead, the simple `i = i` have the same timing.
History
Date User Action Args
2017-12-28 19:39:21serhiy.storchakasetrecipients: + serhiy.storchaka, nascheme, rhettinger, mark.dickinson, ncoghlan, pitrou, christian.heimes, benjamin.peterson, trent, Mark.Shannon, Demur Rumed
2017-12-28 19:39:21serhiy.storchakasetmessageid: <1514489961.2.0.213398074469.issue17611@psf.upfronthosting.co.za>
2017-12-28 19:39:21serhiy.storchakalinkissue17611 messages
2017-12-28 19:39:21serhiy.storchakacreate