#NodeJS : A quick optimization advice

Julien CROUZET
Full Stack Engineering
2 min readOct 7, 2015

--

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 :

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 :

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 !

--

--

Julien CROUZET
Full Stack Engineering

CTO, Senior Full-Stack Web Developer, DevOps, hacker. Father. #NodeJS, #Typescript, #Golang