Reputation: 25
Does V8 optimize multiple function calls that are the same function and arguments? In the example below Variance is called twice with the same arguments.
var Variance = require('variance');
function summary(items) {
return {
variance: Variance(items.value.map((item) => item.value)),
standardDeviation: Math.sqrt(Variance(items.value.map((item) => item.value))),
};
}
Upvotes: 0
Views: 401
Reputation: 106698
v8 does optimize functions called repeatedly with the same arguments, but in your example those are not actually the same arguments (they are different object/array references).
Upvotes: 2