The Runtime Theory
mediumHardwareInternals#explain-the-model#reason-about-tradeoffs

Explain Branch Prediction and Exposing Parallel Work

Explain the model, execution steps, complexity, and limits of branch prediction and exposing parallel work.

TRT practice prompt — not a verified question from a named employer.

The Runtime Theory Team6 min read

Interview prompt

Explain branch prediction and exposing parallel work to an engineer who understands the surrounding system but has not used this technique. Walk from its contract to a concrete operation, then discuss where it fails or becomes expensive.

A strong answer

Branches make program control depend on data. A modern CPU predicts likely directions so it can keep fetching instructions before the condition is fully resolved. Correct predictions preserve pipeline flow; incorrect ones require discarding speculative work and refilling parts of the pipeline.

A loop over sorted values may have a highly predictable branch, while a branch on randomized values may be difficult to predict. Some code can be expressed with conditional operations or grouped data to reduce unpredictable control flow, but those rewrites can increase instruction count or complicate correctness.

A complete answer also calls out the assumptions that control correctness. Instruction-level parallelism is limited by dependencies, branches, and memory stalls. Removing a branch is not automatically faster; the new operations may cost more or prevent vectorization. Benchmark realistic input distributions and check that the compiler generated the intended code.

Close by describing one representative test or measurement. You have a filter with a branch that is true for almost every element. Explain why that may perform differently from a branch that is true half the time, and name one measurement you would collect.

Follow-up questions

Answer the follow-ups in the frontmatter. Use the linked article for the concept and the trace to make the explanation concrete.

This answer walks

Practice follow-ups

  1. 01Which assumption is essential for the approach to be correct?
  2. 02What is the worst case, and how does it change the resource cost?
  3. 03How would you adapt the design if the input or workload became much larger?
  4. 04What boundary test would give you the most confidence in the implementation?

One dispatch a week

The trace behind each question, the tradeoff that explains it, and one technical dispatch per week — no noise.

One technical dispatch per week. No noise.

Not started

Sign in to save your learning progress.

Sign in to save