7 min read
|
Saved February 14, 2026
|
Copied!
Do you care about this?
This article outlines principles and methods for optimizing code performance, primarily using C++ examples. It emphasizes the importance of considering efficiency during development to avoid performance issues later. The authors also provide practical advice for estimating performance impacts while writing code.
If you do, here's more
Jeff and Sanjay outline key principles and techniques for optimizing code performance, drawing from their extensive experience at Google. They emphasize that while premature optimization is often criticized, a focus on performance can yield significant benefits, particularly in that critical 3% of code where efficiency matters. The document highlights the importance of considering performance during development instead of waiting for profiling results, which can lead to a codebase with hidden inefficiencies. This approach often complicates later optimizations and can hinder those who need to improve performance on library code.
The authors provide practical guidance on estimating performance while coding. They encourage developers to choose faster alternatives when possible, without significantly increasing complexity. They suggest assessing the context of the code: test code should focus on asymptotic complexity, application-specific code should consider hot paths, and library code should adhere to established performance techniques. For example, using `absl::InlinedVector` over `std::vector` when dealing with small data sets can prevent unnecessary overhead.
Sanjay and Jeff also introduce a method for quick performance estimation through back-of-the-envelope calculations. This involves estimating the number of low-level operations required, multiplying by their associated costs, and summing the results for a rough resource usage estimate. They provide a detailed table that lists various operations and their approximate latency, such as L1 cache references at 0.5 nanoseconds and disk seeks at 5 million nanoseconds. This foundational knowledge allows developers to make informed decisions about performance without needing to implement every option.
Questions about this article
No questions yet.