3 ms·
This was my thought as well. This is one of the main fallacies of code optimization; unless these functions are called a LOT, you very well might be optimizing
by cortesoft 13y ago
This was my thought as well. This is one of the main fallacies of code optimization; unless these functions are called a LOT, you very well might be optimizing something that is not your bottleneck. You can see the author is missing this point because he talks about going from "20 seconds to 1.5 seconds." He is using those numbers as if they are real use case times, when in fact they are generated from an arbitrary amount of calls to a function.
So many times I will see people make code optimizations of this type to shave fractions of a millisecond from a function call at the cost of complexity, memory usage, etc. Meanwhile, most of the time their program is actually waiting on IO or something of the like.
Blind optimization is counter productive.
- egonschiele 13y agoWhy do you think this is blind optimization? When do you think an optimization like this would be appropriate? Can you give an example of a performance optimization you have made recently?
- jasonlotito 13y ago> Why do you think this is blind optimization? Because it is. It's a clear case of premature optimization. Especially since nothing was offered up to to suggest otherwise. > When do you think an optimization like this would be appropriate? When it's being reported back that it's one of the top bottlenecks. Before that, it's mostly a educational trip. It's great to learn how to write optimized code, but, frankly, removing empty function calls isn't an optimization. > Can you give an example of a performance optimization you have made recently? Eliminating the need for excessive memcache calls by not only changing the objects being called, but also by eliminating the need to make the calls in the first place by intelligently using existing locally cached… cache. If that makes sense. Anyways, that improved performance by ~20ms. It wasn't the slowest call running, but it was the slowest call running that could be optimized at this point.
- nonchalance 13y agoYou don't know what project he was using that gem for. It's very well possible that he did some tests and found that this contracts library was the bottleneck. If that were the case, then the approach makes sense. Although, given the nature of the library, I highly doubt that was the bottleneck
- cortesoft 13y agoYes, it is possible. If this was the case, however, it would have made much more sense to include this information in the blog post. I think people would have gotten more use out of someone explaining the process of finding the bottleneck and then optimizing.