# Quadrupling Code Performance with a Useless If Statement

Original title: Quadrupling code performance with a "useless" if

> Hacker News story 48889148 · language: en · submitted 2026-07-13
> Web version: https://zeli.app/story/48889148
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 6 · by [birdculture](<https://news.ycombinator.com/user?id=birdculture>) · 💬 0
[original](<https://purplesyringa.moe/blog/quadrupling-code-performance-with-a-useless-if/>) · [HN discussion](<https://news.ycombinator.com/item?id=48889148>)

## Summary

While optimizing a compressor, I discovered that adding a seemingly useless conditional check could quadruple loop performance. By tricking the CPU's branch predictor, I broke the dependency chain that was slowing down execution. Although compilers usually remove such code, using a volatile cast forced the optimization, proving that sometimes misleading the machine yields the best results.

## Key quote

> Stupid compiler doesn't realize integers have hardware provenance.

## HN discussion (0 comments)

### [nonadhocproblem](<https://news.ycombinator.com/item?id=48893495>)

> I've also been working on a compressor recently, and the same general idea (letting the compiler know that a data dependency occurs very infrequently, and it should therefore assume none exists to exploit ILP) has allowed me to speed up my decompression by a lot:
>
> https://github.com/welcome-to-the-sunny-side/misa77/blob/777...

### [throawayonthe](<https://news.ycombinator.com/item?id=48890783>)

> lobsters comment points out [[unlikely]] works here for clang
>
> https://clang.godbolt.org/z/r4xYWfPfe
>
> edit: oh the article also mentions it now :)

### [akoboldfrying](<https://news.ycombinator.com/item?id=48889586>)

> This is really surprising! I've never considered the possibility that using an equality test to skip a write that would be a no-op could break a dependency and thus lead to higher perf overall if the "equal" outcome occurs often enough. This might be applicable in many situations where you "edit" some data in-place, but most of the time there are few or no changes.

---

## Cite

- Page: https://zeli.app/story/48889148
- Date: 2026-07-13
- Source: purplesyringa.moe (https://purplesyringa.moe/blog/quadrupling-code-performance-with-a-useless-if/)
- Hacker News: https://news.ycombinator.com/item?id=48889148

## Other languages

- zh: https://zeli.app/zh/story/48889148 · markdown: https://zeli.app/zh/story/48889148.md
- ja: https://zeli.app/ja/story/48889148 · markdown: https://zeli.app/ja/story/48889148.md
- ko: https://zeli.app/ko/story/48889148 · markdown: https://zeli.app/ko/story/48889148.md
- de: https://zeli.app/de/story/48889148 · markdown: https://zeli.app/de/story/48889148.md
- es: https://zeli.app/es/story/48889148 · markdown: https://zeli.app/es/story/48889148.md
