[New-bugs-announce] [issue40222] "Zero cost" exception handling

Mark Shannon report at bugs.python.org
Wed Apr 8 05:41:03 EDT 2020


New submission from Mark Shannon <mark at hotpy.org>:

C++ and Java support what is known as "zero cost" exception handling.
The "zero cost" refers to the cost when no exception is raised. There is still a cost when exceptions are thrown.

The basic principle is that the compiler generates tables indicating where control should be transferred to when an exception is raised. When no exception is raised, there is no runtime overhead.

(C)Python should support "zero cost" exceptions.


Now that the bytecodes for exception handling are regular (meaning that their stack effect can be statically determined) it is possible for the bytecode compiler to emit exception handling tables.

Doing so would have two main benefits.
1. "try" and "with" statements would be faster (and "async for", but that is an implementation detail).
2. Calls to Python functions would be faster as frame objects would be considerably smaller. Currently each frame carries 240 bytes of overhead for exception handling.

----------
assignee: Mark.Shannon
messages: 365974
nosy: Mark.Shannon
priority: normal
severity: normal
status: open
title: "Zero cost" exception handling
type: performance

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40222>
_______________________________________


More information about the New-bugs-announce mailing list