-
-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: use for...of instead of forEach #6307
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## unstable #6307 +/- ##
============================================
- Coverage 80.38% 80.37% -0.01%
============================================
Files 202 202
Lines 19620 19622 +2
Branches 1176 1176
============================================
Hits 15771 15771
- Misses 3821 3823 +2
Partials 28 28 |
Performance Report✔️ no performance regression detected Full benchmark results
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
link to video?
The video was not primarily about for loop performance, just comment in the video. I looked up a few benchmarks yesterday and for...of seems to be slightly better than forEach. Just now, I looked up a few more benchmarks and the results seem mixed though, I also just noticed this was discussed already #1845 (comment). But yeah primary reason is code consistency as we wanna avoid forEach, the points brought up by Lion in #1845 (comment) are more relevant than the performance part of it. If we wanna min-max the performance would likely have to use a regular for loop (based on all benchmarks) but that makes the code less readable in most cases and likely not worth it. |
🎉 This PR is included in v1.15.0 🎉 |
Motivation
Code consistency, marginal performance improvements. I just watched video about node performance yesterday and it was brought up how bad forEach actually is especially if you iterate huge data sets, took this as a inspiration to give our forEach usage another review. We don't use it a lot but might as well clean up remaining forEach usage.
Description
Use for...of instead of forEach
Note: I did not update all occasions as it's either not relevant there in terms of performance or it is just a neat usage of forEach where for...of would make the code less readable.
There was plenty of previous work done by Lion related to this