Work elimination avoids unnecessary computation, data movement, and processing to reduce latency. The fastest code is code that does not execute, but hidden work from language runtimes and operating systems must also be considered. section 7.0
Apply work elimination across the layers that contribute most to execution time:
- Choose algorithms and data structures with low algorithmic complexity; quadratic time can become costly as input grows, while linear or better complexity is often preferable. section 7.8
- Reduce serialization and deserialization, especially repeated JSON conversion; Protocol Buffers and FlatBuffers can lower CPU and memory overhead. section 7.8
- Limit memory-management work through static allocation or object pooling, while accounting for allocation, garbage collection, virtual memory, and physical memory effects. section 7.1 section 7.8
- Mitigate operating-system overhead from scheduling, context switches, background tasks, and network-stack management; some systems allocate resources or bypass the OS. section 7.8
- Precompute results before they are needed, using materialized database views when the added storage cost is acceptable. section 7.8
Measure before removing work
Iteratively benchmark and profile the application, identify bottlenecks in application logic, serialization, or deserialization, and then optimize the measured source of latency. Avoid introducing redundant work while writing new code. section 7.1 section 7.8
