Try, Catch and V8

Recently I found out about how V8 for chrome has issues optimizing certain things and one of the things I found it could not optimize well was try and catch blocks. So I decided to write a quick test to see what it looks like

    console.profile('TryCatch')
    for (var i = 0; i < 99; i++) {
      try {
        console.debug("Hello");
      } catch (e) {
      }
    }
    console.profileEnd();
  

When ran you will find the profile to look something similar to this, mind you it may be machine dependant. Notice the warnings? When you hover over those you will find that chrome hints to you that try catch can not be optimized.

Now lets take out the try catch and profile

    console.profile('NoTryCatch')
    for (var i = 0; i < 99; i++) {
      console.debug("Hello");
    }
    console.profileEnd();
  

Which according to the profile below you will find that this saved time. These profile also came from me typing into console which is slower then actually running the code on the page which may even result in smaller numbers for you.

There you have it ladies and gentleman, try catch indeed can not be optimized in V8