~/talk

Writing fast C code for a modern CPU (and applying it to PostgreSQL)

Talkat PGConf.dev 2025 · 2025-05-13..05-16· [databases, c-and-cpp]
slides:none on file

Modern superscalar CPUs reward predictability: measured on Zen4 and Zen2, branch misprediction stays near 0.03% for 1,000-item patterns but rises to >12% by 25,000 items, doubling loop time; a branchless rewrite and conditional-move use cut mispredictions and halved runtime in microbenchmarks. Hardware prefetching orders give up to 20x slowdown on random access versus sequential. Tools used include perf stat / perf record to find branch misses and Compiler Explorer (Godbolt) to inspect generated asm; PostgreSQL patches and TPCH 5GB tests show modest-to-large gains (one query 10.9s→6.4s).

AI-written summary · about

  1. 0:00Introduction and context
  2. 3:21CPU instruction fundamentals
  3. 6:16Branch prediction mechanics
  4. 10:45Testing and measuring branch prediction
  5. 18:52Mitigating branch misprediction
  6. 21:51Compiler-based optimizations
  7. 26:51Data access patterns and caching
  8. 31:17PostgreSQL memory optimizations
  9. 37:29Heap page layout experiments
  10. 40:21Closing remarks and Q&A
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.