Loop Unrolling Performance

Discussions center on the performance benefits of manual loop unrolling versus compiler-optimized loops, including debates on overhead reduction, branch predictions, and examples across languages like C and JavaScript.

📉 Falling 0.4x Programming Languages
2,850
Comments
20
Years Active
5
Top Authors
#6831
Topic ID

Activity Over Time

2007
10
2008
15
2009
37
2010
94
2011
141
2012
111
2013
167
2014
170
2015
146
2016
178
2017
169
2018
141
2019
179
2020
201
2021
242
2022
241
2023
233
2024
183
2025
181
2026
11

Keywords

RAM CPU OCD youtube.com neighbours.size LINQ IMO nodes.get JDK8 LLVM loop loops compiler performance cache value code stream slower iteration

Sample Comments

marvy May 25, 2020 View on HN

What's not worth it? Loop unrolling? Something else?

ascar Feb 12, 2020 View on HN

It's called loop unrolling and improves performance by eliminating loop control overhead and reducing branch mispredictions. Maybe they had a compiler background :)? /s

machiaweliczny Jun 13, 2020 View on HN

I thoughr this trivial stuff like loops doesn't really matter anymore due to compilator optimizations. Isn't that the case?

ivanjermakov Aug 13, 2024 View on HN

And it would be an order of magnitude slower than plain loop because compiler is not smart enough to optimize it.

scoutt Jun 25, 2020 View on HN

Except when loops unrolls make things faster.

detrino Jul 4, 2015 View on HN

I wonder if this is really faster than just writing it as a loop.

maxloh Oct 27, 2022 View on HN

That seems like a loop.It is slow it is rarely used it doesn't get optimized it is slow

spicyj Jan 3, 2011 View on HN

Doesn't that involve just as much looping as any other solution?

schammy Dec 27, 2010 View on HN

The second I learned this trick, many years ago, I've used it in everything. The argument that it's "slow" is ridiculous. It's like using while(i--) instead of a for() to shave 0.0000001 milliseconds off your javascript loops. Just admit you have OCD and move on ;)

tsimionescu Oct 11, 2024 View on HN

You're comparing apples and oranges. Of course modifying an array or copying it takes way more time than looping. The comparison was not about that, it's about one loop with 10 instructions VS 10 loops each with a single instruction, for the exact same instructions.