Chapter 10. Optimization Examples
It’s finally time to collect all the tools, skills, and knowledge you gathered from the previous chapters and apply some optimizations! In this chapter, we will try to reinforce the pragmatic optimization flow by going through some examples.
We will attempt to optimize the naive implementation of the Sum
from Example 4-1. I will show you how the TFBO (from “Efficiency-Aware Development Flow”) can be applied to three different sets of efficiency requirements.
Optimizations/pessimizations don’t generalize very well. It all depends on the code, so measure each time and don’t cast absolute judgments.
Bartosz Adamczewski, Tweet (2022)
We will use our optimization stories as a foundation for some optimization patterns summarized in the next chapter. Learning about thousands of optimization cases that happened in the past is not very useful. Every case is different. The compiler and language change, so any “brute-force” attempt to try those thousands of optimizations one by one is not pragmatic.1 Instead, I have focused on equipping you with the knowledge, tools, and practices that will let you find a more efficient solution to your problem!
Tip
Please don’t focus on particular optimizations, e.g., the specific algorithmic or code changes I applied. Instead, try to follow how I came up with those changes, how I found what piece of code to optimize first, and how I assessed the change.
We will start in “Sum Examples” by introducing the three problems. ...
Get Efficient Go now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.