ProTip: return vs. exit() - One Way is Way Better



tl:dr; use return;

There are two ways to quit a trigger:

  • exit();

  • return;

Both work, one is measurably better than the other.

A Real World Example

We deployed a bundle I wrote (SSL Expiration) and watched it work.

There are two code fragments in the bundle that caught my eye:

(SSL.certificate === null) & exit();


(subjectsOfInterest.test(subject)) || exit();

We tweaked those lines to use return() and ended up with this:

if ( ! SSL.certificate ) return;


if ( ! subjectsOfInterest.test(subject)) return;

Here are the results:

That inflection point at 16:03 is when we change from exit();   to   return;.

That’s a drop from about 130,000 trigger cycles to about 100,000 trigger cycles.

That’s a 23% drop.

When you are seeing 40Gbps and decrypting 64,000 SSL handshakes per second, improvements like this matter.


I had somebody ask me about this code fragment:

if ( ! SSL.certificate ) return;

That’s valid syntax and is a short way of saying this:

if ( ! SSL.certificate ) {

Same thing, one is shorter, and a wee bit easier to read.


Blog post on the same subject (including video!)