title: Why is there a large performance impact when looping over an array with 240 or more elements?
body: <p>When running a sum loop over an array in Rust, I noticed a huge performance drop when <code>CAPACITY</code> >= 240. <code>CAPACITY</code> = 239 is about 80 times faster. </p>
  
  <p>Is there special compilation optimization Rust is doing for "short" arrays? </p>
  
  <p>Compiled with <code>rustc -C opt-level=3</code>.</p>
  
  <pre class="lang-rust prettyprint-override"><code>use std::time::Instant;
  
  const CAPACITY: usize = 240;
  const IN_LOOPS: usize = 500000;
  
  fn main() {
      let mut arr = [0; CAPACITY];
      for i in 0..CAPACITY {
          arr[i] = i;
      }
      let mut sum = 0;
      let now = Instant::now();
      for _ in 0..IN_LOOPS {
          let mut s = 0;
          for i in 0..arr.len() {
              s += arr[i];
          }
          sum += s;
      }
      println!("sum:{} time:{:?}", sum, now.elapsed());
  }
  </code></pre>