4 ms·
I’d say it happens more frequently than being able to optimize yourself out of a perf problem in my experience. Too many people have taken the “make it correct
by kasey_junk 7y ago
I’d say it happens more frequently than being able to optimize yourself out of a perf problem in my experience.
Too many people have taken the “make it correct then make it fast” advice too far. The definition of “correct” needs to include performance parameters from the beginning because usually the bottlenecks that cause real issues are architectural.
- sagichmal 7y agoIt is my extremely studied experience that this is rarely (read: almost never) the case, and that the far greater risk is of radically less- or entirely un-maintainable code produced by developers who have incorrect intuitions about what needs to be fast.
- kasey_junk 7y agoI suppose this is why they call it anecdotal evidence, as our experiences don’t agree. What I will say is that code that is architecturally correct for the performance requirements necessary is largely not less understandable or unmaintainable than code that is incorrectly designed for the performance context. You don’t end up in the kinds of harder to read optimizations you see in this article in those cases any more than you do under the other case. Another consideration is if your architecture is wrong for your performance space, nothing will help but a rewrite. If your code is optimized in the small too early, you can always rewrite in a way that is more clear.
- joshuamorton 7y agoYou're talking about architectural changes, this article is about, essentially, microoptimizations. Good artchitecture is often faster than bad. Your design should indeed take into account performance requirements. But micro-optimizations like these (almost all of these changes are to avoid linear numbers of reallocations, with the exception of string builder) don't give you order of magnitude speedups unless they're in hot loops anyway. Profile than optimize means profile, then optimize. Designing good software isn't optimization, its designing good software.
- kasey_junk 7y agoLiterally the thread I’m responding too is asking what the value of optimize then profile is. My experience is that you are likely hosed if you’ve gotten to this point in the 80% case. That isn’t to say these techniques have no value, I’ve used many of them myself. But the question was, “how often does it happen that your optimizations are for a flat profile”. For me, the answer is “most of the time”.
- joshuamorton 7y agoAnd the broader context is when talking about micro-optimizations versus reasonable architectures. You shouldn't micro-optimize before profiling, because it likely won't matter. Bluntly, if you have a flat profile, none of the optimizations in this article are relevant anyway. You'll be able to pull out single digit percentage speedups, maybe. The optimize then profile argument isn't meant to be about architecture. Yes, you should build performant architecture. Yes, you should take time to plan a performant architecture before building[+]. But the question of profile than optimize is never (except in the strange way you're bringing it up) about doing macro-optimizations before you've written a line of code. It's almost always in the context of "don't just try to optimize what you think is slow, because you're almost always wrong". Big-O style speedups from architectural changes aren't micro-optimizations, they generally sit outside of that conversation entirely. As an aside, flat profiles are in practice exceedingly rare. Most (useful) programs do the same thing many times. Its very unusual to see a program that isn't, in essence, a loop. And the area inside the loop is going to be hot. The pareto principle applies to execution time too. [+]: Maybe startups who gotta ship it to survive as the exception.
- shereadsthenews 7y agoKanev[1] disagrees. Flat profiles are the common case in actual practice. Edited to add: Since apparently you also work at Google, you should walk over to Svilen's desk and just ask him if profiles of production software are generally flat, or if they generally have hot spots. 1: https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/44271.pdf https://static.googleusercontent.com/media/research.google.c...