Am Montag, 6. August 2012 13:51:06 UTC+2 schrieb Florian Loitsch:
If you have performance critical code you are usually better off not using try/catch. In the current v8 a try/catch statement makes the function non-optimizable. This should (hopefully) eventually be fixed, but even then it will probably still be slower than a function that does not contain any try/catch. Note however that this only concerns the function that actually contains the try/catch statement. Throwing an exception should be fine.
V8 and Dart use type-feedback to optimize code. So if your function never returns the exception-object it will not even know that a different type could be returned. Even if the exception object is returned it could have nearly no impact on performance (depends on the new live code and how the optimizer arranges the type-tests).
If your code is not performance critical try to stick with try/catch since this is the agreed upon way to deal with errors, and makes your code more readable and maintainable.
// florian
Thanks for the quick reply.
I am spending some time on automatic code generation by an interpreter; so the most readable form (whatever it may be) is not of a major concern.
I have asked because have found, but not entirely read nor understood, this old paper "A Study of Exception Handling and Its Dynamic
Optimization in Java" from 2001.
And I have wondered if in the special case that I have described in my second post, that the JIT could maybe maintain efficient code inlining per alternative code path identified as either:
- the regular path
- the exceptional path