From the course: Go Performance Optimization

Why optimize?

- [Instructor] Let's take a look at performance optimization and why are we doing it? And the two main reasons in my opinion first are the customers. When your application responds fast, customers are happy they're less likely to leave. When you're talking about user interfaces the rule of thumb is, that one-tenth of a second looks immediate to us humans. So this is the goal we try to achieve. The second reason is well, money. In these cloud environments today we are charged by CPU, by memory, by bandwidth. If you can optimize your code to consume less resources you are going to save money. One of the things I like about performance tuning is that you need to know a lot of things and there are a lot of things to explore. You need to know about computer architecture, you need to understand how data is sent over the network, you need to know about databases and how you can efficiently store and query data. You need to understand data structures and algorithms and you need to even know how the Go runtime works. Let's have a look at some rules by Rob Pike. The first rule is that you can't tell where a program is going to spend the time. Every time we go to a customer and do performance optimization, it's another surprise. The second rule is to measure. Every time we want to make performance optimization we first measure how fast the code is running or how much memory it consumes. Rule three says that, "Fancy algorithms are slow when n is small." You need to know that you have large enough data to justify these fancy algorithms. The fourth rule talks about fancy algorithms that are buggier. Every time we do optimization, there is a risk. So you need to make sure that you know the risk and that is acceptable in your situation. And the fifth rule is that data dominates. By far, data structures and algorithms are going to give you the biggest performance boost. But we are going to look at other methods as well.

Contents