Hacker News new | ask | show | jobs
by jefflombardjr 1659 days ago
They are 100% doing it. A lot of really bright people work on the engines/compilers.

The problem is telling individuals to focus on optimization.

Let's use javascript as an example. Say you need to transform an array. You can use `.map` or a `for` loop in javascript.

You see a lot of articles like this https://dev.to/henryjw/array-map-much-slower-than-for-loop-5... that say a `for` loop is faster. And sometimes it's true.

By the logic of the original article, you should hyperoptimize your code. The problem is. If everyone writes `for` loops instead of using `map`. When map eventually becomes more efficient there's all that garbage code out there that has to be refactored.

Ignoring the problems associated with benchmarking - this for example claims map now being faster than for loops. https://leanylabs.com/blog/js-forEach-map-reduce-vs-for-for_...

It comes down to return on effort. We only have so much effort to put at solving this problem. You maximize your return on effort by having a clear separation of responsibility. In this case the individual's responsibility is to write code to the latest spec. The institution's responsibility is to make the code written as efficient as possible.

A single website saving .000000001 ppm of carbon (exaggerating) is just never going to be worth the effort. But a compiler improvement on all websites running javascript. Now that's totally worth it.

Further reading behind this logic: https://www.goodreads.com/book/show/3828902-thinking-in-syst...

https://stackify.com/premature-optimization-evil/

Code Complete (chapter 25.2) https://www.oreilly.com/library/view/code-complete-second/07...

2 comments

P.S. Thoughts: This might be the case for software engineering, but might break down in other domains and should be applied carefully elsewhere.

For example recycling plastic is your responsibility - but what if your city burns plastic recycling? What do you do? Do you continue to buy plastic blame the companies for using it and the city for burning it? Why should the individual be penalized?

This seems more gray to me, like yeah okay I'm going to reduce the amount of plastic I buy in that case. And there are alternative like paper. In programming it feels more black and white. There is map and it serves a single purpose.

> For example recycling plastic is your responsibility - but what if your city burns plastic recycling? What do you do? Do you continue to buy plastic blame the companies for using it and the city for burning it? Why should the individual be penalized?

Unfortunately, while what you are saying is the conventional wisdom, it turns out that it’s also insidious propaganda from the plastic and beverage industry created to evade responsibility for their products.

According to the Changing Markets Foundation, which has extensively tracked the history of this issue

> the industry has successfully shifted the blame and responsibility for plastic pollution from the corporations to consumers and public authorities, all while promoting recycling as a convenient excuse to produce ever more plastic. We see how fake environmental groups and increasing numbers of new voluntary initiatives are used to distract from accountability, while legislation – such as plastic-bag bans and bottle bills – has been furiously fought against for years.

Inefficiency is not due to the choice between for and map, but due to them executing many times. When you run a quadratic algorithm, it doesn't matter whether it's implemented with for or map, it's inefficient in both cases. Premature optimization is when you optimize based on assumptions as opposed to diagnosis of the problem. You believe the problem is due to for/map based on a priori reasoning. You also believe your code needs hyperoptimization before it had basic optimization. Well indeed why not, your code can't possibly be bad?