Please improve gen js

I did a quick search on what the current state of JS engines is in regards to loop unrolling. According to 1039458 - Unroll tight loops Firefox can in theory do it itself but it’s not activated by default. Didn’t find anything about V8 but according to performance - JavaScript - Are loops faster than discretely writing line-by-line? - Stack Overflow it at least didn’t yet happen mid 2016.
Looks like it does indeed still make sense to unroll loops for JS.
Does not seem to make sense for C++ at all though, this basically just hides information from clang/gcc/msvc which all can do loop unrolling themselves and can combine it with other optimizations in fancy ways. Probably the same for Java and C# but I don’t know for sure and I don’t care enough for it to have a closer look.

PS: Please don’t use a variable for your loop bounds - if anything it’ll just make things slower.

2 Likes