Wednesday 

Room 2 

11:40 - 12:40 

(UTC+02

Talk (60 min)

Are You Smarter Than A Branch Predictor?

A single unpredictable branch can quietly dominate your execution time. In this (very) high energy, interactive session (part performance talk, part game show) the audience becomes the branch predictor. Participants will see small C++ snippets inspired by real world production code and vote on which version is faster. Novelty erasers included for correct answers :)

C++
Technique

Each challenge will uncover another piece of how modern processors handle control flow. We'll build a practical mental model of branch prediction, explore what happens when the CPU gets a prediction wrong, and, importantly, learn how to identify the branches that are actually costing you performance.Using animated visuals, annotated assembly, benchmarks, profiling tools, and hardware performance counters, we'll investigate questions such as: How does a CPU predict a branch before it has executed it? What makes a branch predictable or unpredictable? How can you tell whether branch mispredictions are really your bottleneck? And once you find one, what can you actually do about it?Along the way, we'll explore branch prediction and the cost of misprediction, conditional moves versus branches, indirect calls and virtual dispatch, compiler transformations, data layout and branch predictability, and cases where supposedly clever "branchless" code actually makes performance worse.We'll also look at how popular compilers such as GCC, Clang, and MSVC can transform the same source code in surprisingly different ways, and why looking at your source code alone isn't enough to know what branches the processor will actually execute.


Yes, some of these are microbenchmarks. But they expose patterns that show up in real systems, especially when profiling points to control flow as your bottleneck. We'll discuss how to benchmark these changes without fooling ourselves and how to use profiling and hardware counters to move from "I think this branch is slow" to evidence.The examples are shown in C++, but the underlying principles apply to any compiled language targeting modern CPUs.Attendees will leave with:

  • A concrete mental model of how branch prediction works on real processors
  • Practical techniques for finding branches and identifying costly branch mispredictions
  • Patterns for making control flow more predictable, and knowing when branchless code helps or hurts
  • An understanding of how compiler decisions affect the branches that actually reach the CPU
  • A workflow for validating performance changes with benchmarks, profiling tools, assembly, and hardware counters
  • A clearer understanding of when not to micro-optimize

Michelle D'souza

Michelle Fae D'Souza is a software engineer at Bloomberg, where she develops systems for the company's data license solution, delivering trading and financial data to firms worldwide. She has also worked on real-time, low-level production systems. An active member of Bloomberg's C++ Guild, she also serves as a Technical Rep within the firm.
Michelle earned a bachelor's degree in computer science from the University of California, Berkeley, where she was a Davis Scholar and President of the Computer Science Honors Society. She regularly speaks about C++, performance, and systems-level topics.