#NodeJS : A quick optimization advice

Julien CROUZET
Full Stack Engineering

--

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 !

--

--

Full Stack Engineering
Full Stack Engineering

Published in Full Stack Engineering

Using magic to make IT things work and keep people happy

Julien CROUZET
Julien CROUZET

Written by Julien CROUZET

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

Responses (23)