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 Mark.Shannon
Recipients Mark.Shannon, erlendaasland, gvanrossum, iritkatriel, xtreak
Date 2021-12-14.20:21:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1639513317.25.0.162597426296.issue45292@roundup.psfhosted.org>
In-reply-to
Content
PR 29581 resulted in a 1% slowdown, which is not terrible, but code not using except* should not be slowed down at all.

IMO, the way to avoid the slowdown is to implement except* using the existing instruction set (perhaps with a few minor additions)

We already implement try-finally, named except blocks and with statements without any complex bytecodes (except perhaps WITH_EXCEPT_START).

These used to involve a lot of state and more complex bytecodes. So it is possible to make these simplifications,
but it does take work.


There are a number of techniques we can use:

If any state is needed, push it to the stack as we do with `ctx.__exit__` in the with statement, and when pushing f_lasti in exception handlers.
Duplicate code paths when the semantics differ in different cases, as we do for finally blocks.
If anything is too complex to handle on the stack, put it in a temporary variable.
Be liberal in your use of virtual try-excepts (SETUP_FINALLY, POP_FINALLY pairs), as zero-cost exception handling should keep the cost down.


It may be too late for this advice, but if I were writing the `except*` implementation from scratch, I would:

1. Sketch out the pseudo Python that a try-except* would map to. This is a good opportunity to discover any design bugs that might result in undesirable behavior for corner cases.

2. Implement the translation in the compiler, not worrying about any redundancy or inefficiency, just correctness.

3. Look to improve the above, either in the compiler front-end, or by replacing inefficient code patterns in the back-end. Handling the optimization in the backend has the advantage that other code might benefit as well.
History
Date User Action Args
2021-12-14 20:21:57Mark.Shannonsetrecipients: + Mark.Shannon, gvanrossum, xtreak, erlendaasland, iritkatriel
2021-12-14 20:21:57Mark.Shannonsetmessageid: <1639513317.25.0.162597426296.issue45292@roundup.psfhosted.org>
2021-12-14 20:21:57Mark.Shannonlinkissue45292 messages
2021-12-14 20:21:56Mark.Shannoncreate