3 ms·
> First and foremost, you really ought to understand what order of magnitude matters for each line of code you write. And that is: amount of time that will eve
by kazinator 11y ago
> First and foremost, you really ought to understand what order of magnitude matters for each line of code you write.
And that is: amount of time that will ever be spent in it across all deployments and execution instances, versus how long it takes to develop, taking into the cost of that CPU time and development time.
You could spend, say, $100 of development time such that the total CPU time saved over the entire installed base of the code over its lifetime is worth $5.
Secondly, even if the saving is greater than $100, that means nothing if it's not recouped! That is to say, suppose you spend $100 to optimize something, and the entire user base saves $200 worth of CPU time over the next 25 years, when the last installation of the program is shelved. Only, oops, the users never paid a single penny more for the improvement. Moreover, suppose the improvement was only marginal and in some relatively obscure function, so that it didn't help to sell more of the program to more users. So in the end, you're just out $100.
> Mostly this quip is used defend sloppy decision-making, or to justify the indefinite deferral of decision-making.
Here is the thing. An program optimized for performance is "bad" because it's hard to change its organization later (for instance when it needs to be optimized). It's harder to debug, too.
We consciously avoid optimizing code in order to have the code in a state that is easier to work with.
But we must ensure that we actually achieve this. In effect, we should be actively optimizing for good program organization, rather than just focusing on a negative: not optimizing for performance.
Or optimizing something other than performance, and good program organization.
A really bad approach is, for example, "optimizing for the minimum amount of time I ever have to spend learning effective use of my programming language, libraries, and existing frameworks in my project".
You get code that isn't performance optimized, avoiding the "root of all evil", but it's garbage in other ways.