To better understand optimization in programming, I'd like to ask some general questions:
- What does it actually mean to optimize a program?
- How do you know when it is time to make optimizations?
- What does the process of optimization look like?
- I often see people repeating Knuth's "premature optimization is the root of all evil" quote. Would you agree that this quote is usually taken out of context, or possibly even used completely wrong? What does the quote actually refer to?
- For a specific example of the above: I often allocate a large chunk of memory up front, then use that chunk as a basic arena for further "allocations". (This is very similar to what Casey does in Handmade Hero.) From the start of a project, I care about how memory is used, how things are put into memory, and how the CPU accesses memory.
A friend of mine tells me that I don't need care about things like this until much later, if at all. He then inevitably repeats the "premature optimization" quote and tells me things like "just use 'malloc' or 'new' everywhere because it's easier". How would you respond to this? What draws the line between caring about things like memory upfront and "premature optimization"?
Thanks!