As an hypothetical example we’re going to calculate the sum of 2 and 5 over and over again. One billion times:
When I run this with
node calc.js on my machine it takes 444ms.
Function inlining internally rewrites the code to get rid of the call to
add inside calculateTwoPlusFive:
This optimization makes the code a lot faster.
You can see how much faster by passing the
--nouse_inlining flag to Node:
node --nouse_inlining calc.js
Now doing the calculation takes 3.7s, almost 10 times as much as when V8 uses inlining.