Re:Python 3.11: “Zero cost” exception handling
by pca006132 on Wednesday October 06, 2021 @09:41AM
(#28773062)
Zero cost refers to the cost when no exception is thrown, not the overhead of exceptions. It may be more expensive throwing an exception under "zero cost" exception model, as throwing an exception may require parsing some data in the executable. (I'm not sure about the implementation, so this is just a may...)
[ Parent
| on HN ]
Re:Python 3.11: “Zero cost” exception handling
by SideburnsOfDoom on Wednesday October 06, 2021 @10:56AM
(#28773896)
> Zero cost refers to the cost when no exception is thrown, not the overhead of exceptions
There are recent benchmarks where .NET "zero cost when an try-catch block is present and exception not thrown" turned out to be significantly slower then the alternative without such a block.
It turns out that the try-catch block is a barrier across which some optimisations and re-organisations (e.g. method inlining) cannot happen, and that the compiler & JIT normally do a lot of these. So it might be "zero cost" but it might also prevent wins.
Edit: see here https://blogs.msmvps.com/peterritchie/2007/06/22/performance...
https://stackoverflow.com/questions/1308432/do-try-catch-blo...
Re:Python 3.11: “Zero cost” exception handling
by masklinn on Wednesday October 06, 2021 @11:07AM
(#28774043)
Makes sense. Basically it’s zero-cost for exceptions-unaware code. I don’t know if it’s been changed with more modern jits but used to be chrome was unable to jit functions with try statements (similar to functions using `arguments` or `with` I think).