Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't V8 optimize try-catch-finally?

Why is it that V8 is unable to optimize try-catch-finally blocks, when other prominent runtimes (SpiderMonkey, Chakra) seem to have no problems with this?

like image 947
csvan Avatar asked Jun 30 '16 11:06

csvan


1 Answers

There is no particular reason other than the issue has a relatively low priority.

This will be optimized at some point

Check this out chromium v8 issue 1065

If you target v8 you can move try-catch to separate function, but you should do this only if it's a real performance issue otherwise its just premature optimization.

"Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%" - Donald Knuth

The only function that most likely will never be optimized are

  • Functions with a "debugger" statement
  • Functions that call eval()
  • Functions that contain a "with" statement

Other issues with optimization should be fixed at some point.

like image 132
Pawel Wodzicki Avatar answered Oct 04 '22 00:10

Pawel Wodzicki