I like the functional programming paradigm which according to me produces cleaner code and easier to understand, but I'd like to know if the performance loss is significative or not.
Let's take the example of a function that adds a new property to an object. A non-functional approach would look like this:
const addProp = (obj, prop, val) => {
obj[prop] = val; // Mutate the object
return obj;
}
While the functional approach would look like this:
const addProp = (obj, prop, val) => ({ ...obj, [prop]: val }); // Shallow clone
What's the cost of the shallow clone compared to the object mutation? I'd like to know how much functional programming patterns degrade performance (if they do).