Optimizing code in the hot path; with examples from tuple deformation
summary
Optimizes PostgreSQL tuple deformation by shrinking attribute metadata, precomputing cached offsets, replacing per-bit null checks with a SWAR null-bit trick, and turning indirect calls into sibling/tail jumps; profiling with perf record and perf stat shows instructions-per-cycle rising and runtime dropping from ~305 ms to ~206 ms after those patches, and a proposed selective deforming method cuts the benchmark to ~55 ms (≈5.5× faster). Benchmarks and CPU assembly analysis validate each change.
AI-written summary · about
chapters (12)
- 0:00Introduction and overview
- 1:31Profiling with Perf
- 8:55Tuple deformation basics
- 12:28Optimizing attribute struct
- 15:25Removing branching in macros
- 20:24Simplifying null checks
- 22:51Benchmarking strategies
- 24:56Sibling and tail calls
- 28:52Bit manipulation with SWAR
- 33:52Proactive offset caching
- 37:48Selective tuple deformation
- 41:43Summary and Q&A
