Comment #3 on issue 1065 by [email protected]: try catch incurs an unexpected performance penalty
http://code.google.com/p/v8/issues/detail?id=1065

V8 does unwind the stack (can you think of any other way to implement throw/catch?). The real performance problem is that functions containing try/catch are not optimized.

* I think catch-bound variables are allocated in the heap mainly for historical reasons. They originally used the same implementation machinery as 'with'. This was changed in 2011. But when it changed, V8 kept the heap allocation as part of the old implementation. I can't think of a super compelling reason not to stack allocate them, other than the implementation effort and the relatively low priority. They do take up extra space in the stack frame and they do require initialization with some value that is safe for GC.

* You should definitely profile before you conclude this is a performance problem. For reads, the code contains only an extra register-register move in most cases. You'd have to be reading the catch variable in a loop to even observe the difference. For heap writes, there is a write barrier for the garbage collector. But who writes to a catch-bound variable anyway? If you're doing that in a loop there is a simple workaround --- don't.

* V8 optimizes at the granularity of a whole function. It is not simple to have a function which is partly optimized and partly not (with a stack frame that is a mix of optimized/unoptimized) --- that's the principle at play when a programmer abstracts out part of a body into a separate function. I would estimate that supporting such behavior in the optimizing compiler would be more difficult than just supporting try/catch in the first place.

--
You received this message because this project is configured to send all issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to