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).
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...