4 ms·
You can pretty much just drop that "micro-". With very few exceptions, you really shouldn't optimize until you have accurate measurements of what is going on.
by ska 11y ago
You can pretty much just drop that "micro-". With very few exceptions, you really shouldn't optimize until you have accurate measurements of what is going on.
Update: To me, a lot of responses here conflate "optimization" with "design". From where I'm sitting, "optimization" means making adjustments to and existing solution to make it faster. That has nothing to do with choosing an appropriate language or toolset, and limited amounts to do with overall design. Yes, sometimes you must project forward a bit, for example knowing you'll be able to optimize out exponential behavior with a better data structure, say.
But often people do too much, too early, with too little information.
- jules 11y agoThe qualifier "micro-" is right. You have to pick the language, and design your data structures and algorithms for efficiency from the ground up. Doing that after the fact is a nightmare, and downright impossible if you made the wrong language choice.
- emsy 11y agoI wanted to make a similar comment but I don't understand what you mean by language choice. In my experience broad design choices can make it different to optimize later on, if you mean that.
- mrich 11y agoChoosing Python for some memory/cache-bound program may turn out to be the wrong choice, and you need to rewrite it in C/C++.
- ska 11y agoThat isn't what "micro-" typically means in this context. You are talking about design. real micro optimization examples: order of operation in an inner loop. Changing memory alignment to facilitate vectorization, figuring out your compiler is doing something dumb and tricking it into better code generation for that area,etc. If you are looking at generated assembly, chances you are doing micro-optimization.
- deleted 11y ago[deleted]
- jules 11y agoI may have expressed myself in a confusing way, but it was in fact my intention to express that while you don't need to worry about micro-optimization up front, you do need to worry about designing for efficiency up front.
- ska 11y agoAbsolutely agreed - just don't think that describes optimization, and my comment was about optimization.
- vmarsy 11y agoI hope everyone agrees on this. How would one know if the optimization was successful if there is no measurements to prove it!
- beagle3 11y agoWhile that's true, it is often confused with the (wrong) assumption that: "don't try to do things efficiently; just measure later and redo the slow parts". More often than not, if you don't think about performance characteristics beforehand, then -- after taking care of the low hanging fruit -- you find out that time is wasted all over, and there's no specific culprit that's making things so slow; at which point, you need to rewrite the whole thing. Efficiency should be considered from the beginning in most projects, or later optimizations will be on the scale of "massive undertaking" to "complete rewrite".
- deleted 11y ago[deleted]
- munchbunny 11y agoWe can differ on what we mean by "micro," but I think our intent is more or less the same. There is such a thing as anticipating performance problems and designing for them, and there is such a thing as losing sight of the performance needs of the code you're writing. At the end of the day, it's another expression of the 80/20 rule: do the 20% of the optimization work that affects 80% of the runtime. But outside of general knowledge of where the inner loops are, you won't know what that 20% of code that touches 80% of runtime is until you measure.