title: Any way to force js engines to unroll a loop?
body: <p>I have a performance critical queue container that does a lot of random inserts/deletes. In my container class, I have a fixed size Uint32Array called updates and in my insert logic, I need to compare a value to every value in this update array.</p>
  <p>Originally, I did it simply like this:</p>
  <pre><code>const u = this.updates;
  for (let i = 0; i &lt; u.length; i++) bucket_offset += bi &gt;= u[i];
  </code></pre>
  <p>Then, just as I was putting finishing touches on the container and just screwing around, I tried unrolling said loop</p>
  <pre><code>const u = this.updates;
  bucket_offset += (bi &gt;= u[0]) + (bi &gt;= u[1]) + (bi &gt;= u[2]) + (bi &gt;= u[3]) + (bi &gt;= u[4]) + (bi &gt;= u[5]) + (bi &gt;= u[6]) + (bi &gt;= u[7]) + (bi &gt;= u[8]) + (bi &gt;= u[9]) + (bi &gt;= u[10]) + (bi &gt;= u[11]) + (bi &gt;= u[12]) + (bi &gt;= u[13]) + (bi &gt;= u[14]) + (bi &gt;= u[15]);
  </code></pre>
  <p>And turns out this is around 10x faster on chrome, making the whole insert ~30% faster.</p>
  <p>After that revelation, I'm looking for a way to make the VM understand that its okay to unroll that loop, after all, this.updates.length is a constant.</p>
  <p>At the end of the day, it can stay the way it is but I'd prefer a loop since it would just look nicer. Any ideas?</p>
  <p>My main target is the Chrome browser running on V8.</p>