In the vast majority of cases, the readability/maintainability concerns are more important than the performance implications, which is why I prefer .map/.reduce and other higher-order friends, over simple for loops (or .forEach loops).
so why the hell are every friggin website on earth running at 10fps !
Assuming it is a genuine question and not a rhetorical one, here are a few reasons:
Because even a single synchronous piece of code can slow down the main thread and stall the whole UI. E.g., just synchronously reading or writing document.cookie in an onscroll handler might slow down UI.
Because you might have weird CSS (or JS changing CSS) that forces redraw when nothing changes on the page. Try opening Console > Rendering and select "Paint flashing". If you see a lot of stuff being redrawn (flashed) when it should not change, try simplifying your styles.
the performance bottlenecks front-end UIs almost always come from network requests or DOM operations, and not from the speed of list manipulation operations.
19
u/jcelerier Apr 17 '19
so why the hell are every friggin website on earth running at 10fps !