2 ms·
It seems to mostly be about optimization. There are some good points, but, like so many of these topics, it enters the world of "orthodoxy," where we all have
by ChrisMarshallNY 7y ago
It seems to mostly be about optimization.
There are some good points, but, like so many of these topics, it enters the world of "orthodoxy," where we all have to do things the same way, everywhere, and in all places.
Optimization (effective optimization, anyway) is a fairly intense process. For one thing, common sense doesn't really apply. What seems to be an optimization can sometimes do exactly the opposite, like breaking cache, or introducing thread contention.
It can also introduce really weird bugs, that are hard to track down, and strange code structures that relatively inexperienced maintenance programmers may have difficulty grokking.
It's all about the metrics. Profilers are your friend.
Also, in many cases, optimization isn't necessary at all. If the code controls response to a tab selection, then the code that redraws the tab is likely to be executed in a separate thread, anyway, and done at the pleasure of the OS. Why bother optimizing the lookup index to save a few microseconds?
Another matter, entirely, when we are iterating an Array that is many thousands of elements long. In some cases, using HOF can actually decrease the performance (but YMMV). I have sometimes had to replace a map() with a for.
We measure and find hot spots, and then concentrate on them.
If we are working with mobile or embedded, then we also need to worry about power consumption. That's a fairly fraught area, right there, and optimization can actually cause power drain.
- gav 7y ago> It's all about the metrics. Profilers are your friend. In my experience, profilers are not used nearly enough. They also tend to be used when systems are at or near crisis already. It's way more valuable to have profilers run at on every build (or at least every deployment) to see if there's regressions. Having performance metrics in production to continually track key metrics is critical. All software is built with assumptions that impact performance and all of a sudden those can be invalidated. There's a lot of O(N^2) code that's just fine right up until it explodes. Some examples I've run across: - A query API that could contain metadata saying "throw away this result and re-query with these values instead" that worked great for years because it only impacted a single-digit percentage of queries. One day the users decided to really start using this feature, and found that the impact of executing a query that took 100ms and running another 100ms query was way worse than doubling the average. - A system where you could configure plugins to make "pretty" URLs by running a list of regular expressions. Again, this worked great for years until both the number of URLs and the number of plugins increased and the 25% of the page generation time was spent running regular expressions.
- ChrisMarshallNY 7y agoGood advice.