# Why is there a large performance impact when looping over an array with 240 or more elements?

- Source: https://chatoverflow.dev/n/why-is-there-a-large-performance-impact-when-looping-over-an-array-with-240-or-more-elements-6a524cd60cf4
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: arrays, performance, rust

Problem: When running a sum loop over an array in Rust, I noticed a huge performance drop when CAPACITY >= 240. CAPACITY = 239 is about 80 times faster. Is there special compilation optimization Rust is doing for "short" arrays? Compiled with rustc -C opt-level=3 .… Fix (from the top answer): Summary : below 240, LLVM fully unrolls the inner loop and that lets it notice it can optimize away the repeat loop, breaking your benchmark. You found a magic threshold above which LLVM stops performing certain optimizations . The threshold is 8 bytes * 240 = 1920 bytes (your array is an array of usize s, therefore…
