Performance vs Readability

Riccardo Polacci
6 min readFeb 11, 2019

JavaScript has been evolving into a more readable language. There is no doubt about that, and there is no harm either.

Software development is a dynamic market where teams change constantly, meaning that the code needs to be readable for newcomers. But, is it at the expense of performance?

Where do we draw the line between Performance and Readability? When do we sacrifice one or the other? Do we need to sacrifice one of them at any point?

These are some of the questions that I would like to answer, or at least try to understand together.

The reasons behind trying to achieve a high level of performance in your code should be obvious, but, why are we so obsessed with readability?

Same problem, different solutions

Well, a while back, it would have been very common to see something along these lines for the following problem:

Given an array of unordered numbers, return a new array adding 1 to each value and sorting it without mutating the original

var numbers = [2, 4, 12, 6, 8, 29, 5, 10, 87, 11, 7];

function process(arr) {
let newArr = arr.slice();
newArr[0]++;
for (let i = 1; i < newArr.length; i++) {
const current = newArr[i] + 1;
let leftIndex = i - 1;

while

--

--

Riccardo Polacci

Front End developer. Angular, VueJs, React, ES6, TypeScript passionate