#NodeJS : A quick optimization advice

1 min read Original article ↗

Press enter or click to view image in full size

Julien CROUZET

Can you spot the difference between these two files :

that can explain a 50% performance gain :

If you don’t, it’s normal, you try to read the code abstracting the comment ; it was slightly changed :

Press enter or click to view image in full size

What the ???

The small changes made the function body of add() growing over 600 character. v8 optimizer (crankshaft) inlines the functions whose body length, including the comments, is less than 600 characters.

The 600 character limit can be tweaked via the max-inlined-source-size of the node command :

Press enter or click to view image in full size

So when you have a function or callback that’ll be called repeatedly, try to make it under 600 characters (or your tweaked value), you’ll have a quick win !