Has code optimization ever been disastrous?
Is micro-optimization important in coding?
Whenever someone after optimization I am reminded of the quote from Michael A. Jackson
The first rule of program optimization: Do not do it.
The second rule of program optimization (only for experts!): Do not do it still.
Quote from Wikipedia corrected for British English. * 8th ')
The second rule implies that profile Your code and just spend time tweaking things that make a difference.
When you programmed in Assembly, your father's assertion was correct. But that's a lot closer to metal than most people code nowadays. Today even can to attemptOptimizing yourself (without profiling) will cause your code to run slower than if you had done something the more usual way, since the Common Way is more likely to be optimized by modern JIT compilers.
Even in C, you have to be pretty good at optimization to know more about how to optimize a section of code than the compiler does.
If you don't know a lot of what Ulrich Drepper is talking about in his excellent article What every programmer should know about memoryThen you are probably even on a loser trying to optimize yourself. In contrast to the title of the paper (which is actually a tribute to David Goldberg's equally fantastic What every computer scientist should know about floating point arithmetic) is that lack of understanding at this level doesn't necessarily stop you from being a good programmer, just a different kind of programmer.
vs. in PHP
I don't know PHP so it's not clear what to do. I can infer it from context, but this means that it is similarly obscure to novice PHP programmers) and possibly even lead to experienced programmers taking it twice. This is the kind of idiomatic Using language that can make maintenance a nightmare.
In addition, there is no guarantee that just because it is more efficient now is always more efficient. An optimization now may not be an optimization in the next year or 10 years. CPUs, systems, and compilers improve and change over time. If the performance of PHPs is an issue, PHP may be changed in the future, all isset () optimizations may need to be removed in order to optimize the code one more time.
Each optimization has the potential to become a future Anti-optimization, so should be viewed as a possible code smell to be kept to a minimum.
An example from personal experience
As an example of such Anti-optimization I once had to clean up a huge code base that was filled with code of the form because someone assumed that a floating point was multiplied always becomes more expensive than a branch. With the original target architecture, this optimization resulted in code executing an order of magnitude faster, but times change.
When we tried using this code on a more modern, high-pipeline CPU, the performance was terribly poor - any of these instructions result in a pipeline flush. By simplifying all of these lines of code to just one, the program on the new architecture ran an order of magnitude faster, thereby reducing performance Anti-optimization has been restored.
The problems that we usually have to optimize today are very unlike the ones we had to optimize 20 or even 10 years ago.
Then we worried that we could do most of the work per clock cycle, now we're more worried about pipeline flushes, branch errors, and CPU-level cache errors, but locks and interprocess communication are becoming too much = More important if we move to multiprocessor and multiprocessor architectures. Drepper's article can really help you understand many of these issues.
- RFID is an old technology
- How did the 4th Hokage seal Kurama?
- Why ancient civilizations needed numbers
- When should I stretch in bodybuilding?
- What does simply mean in German?
- What kind of evidence would be enough
- How difficult is the police hiring process
- Why is Pikachu so damn cute
- Which of the axis powers came first
- What is Hausa
- What are some misunderstandings about burlesque
- Can I donate blood if I have a tattoo?
- Which backend did Airbnb use
- Is the mind subjectively objective or something else
- What are amazing health facts
- Miniature horses are born in the wild
- Is TB curable
- What do you think about project management
- What is my gluten
- How can I hire good people
- How slow was your first computer
- What are eye trackers tracking
- Can ejaculation accelerate penis growth
- Which fruit name starts with AV