Avoid Iterator allocation in Wasm Backend operations
Add memoryOptimizedForEach and memoryOptimizedForEachIndexed to avoid allocating an Iterator (index-based for loops, not default iterator for loop) and apply them to Wasm Backend for better performance overall. This could also be done for intermediate operations like map, mapIndexed, and others but this is only a little change focused on improving memory consumption in Wasm Backend operations and compilation
I would prefer this to be named based on how it behaves, not a relationship to the "normal" forEach.
If you run this new function on non-random access-based list, you actually thrash the cache lines of the CPU making it very much not memory optimized. Heap allocation and virtual dispatch counts are not the only memory that needs considered.
I tend to call these indexBasedForEach which describes the implementation, and hopefully makes it more obvious that it's a Bad Idea™ to use on something like a linked list.
i tried to mantain consistent naming so thats why i changed to mention the index access in the kdoc. renaming it!
@ilgonmic not sure the reviewers are correct
cc @bashor