# pipelining

Published articles for pipelining.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Branch Prediction: Why an if Inside a Hot Loop Costs Milliseconds

DevFeed: [Branch Prediction: Why an if Inside a Hot Loop Costs Milliseconds](<https://devfeed.tech/articles/branch-prediction-why-an-if-inside-a-hot-loop-costs-milliseconds-39571.md>)

Original publisher: [Read original article](<https://ankit-rana.com/logs/19-branch-prediction-loop-unrolling/>)

Author: hello@ankit-rana.com

Published: 2026-03-21T00:00:00Z

Content type: tutorial

Language: en

Sources: [Ankit Rana | Mechanical Sympathy](<https://devfeed.tech/sources/ankit-rana-mechanical-sympathy.md>)

Topics: [cpu](<https://devfeed.tech/topics/cpu.md>), [Hardware](<https://devfeed.tech/topics/hardware.md>)

Tags: [branch](<https://devfeed.tech/tags/branch.md>), [branch-prediction](<https://devfeed.tech/tags/branch-prediction.md>), [cpu](<https://devfeed.tech/tags/cpu.md>), [cycles](<https://devfeed.tech/tags/cycles.md>), [loops](<https://devfeed.tech/tags/loops.md>), [optimization](<https://devfeed.tech/tags/optimization.md>), [performance](<https://devfeed.tech/tags/performance.md>), [pipeline](<https://devfeed.tech/tags/pipeline.md>), [pipelining](<https://devfeed.tech/tags/pipelining.md>), [sorting](<https://devfeed.tech/tags/sorting.md>), [systems](<https://devfeed.tech/tags/systems.md>), [wall-clock-time](<https://devfeed.tech/tags/wall-clock-time.md>)

### AI overview

This tutorial explains how CPU pipelining and branch prediction affect performance in hot loops. It describes the cost of mispredictions and suggests sorting data to create predictable branch patterns or using branchless techniques and loop unrolling, while recommending measurement on the target workload.

### Source excerpt

CPUs pipeline instructions and speculate on branch outcomes. A misprediction discards the speculative work and flushes the pipeline at roughly 10 to 20 cycles. In a million-iteration loop with random branch outcomes, those flushes dominate runtime. Sorting the data so the branch resolves the same way for long runs, or removing the branch entirely with a mask or 0/1 multiplier, is what recovers the time.