google / google/closure-compiler
Consider replacing forEach, filter, reduce...
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
Hi,
when parsing the JavaScript input consider replacing methods like forEach with for constructs in order to improve performance significantly.
For example:
```javascript
const numbers = [ 10, 20, 30, 40, 50 ];
const numbersLessThan30 = numbers.filter(number => number < 30);
// OUT [ 10, 20 ].
```
Should become:
```javascript
const numbers = [ 10, 20, 30, 40, 50 ];
const numbersLessThan30 = [];
for (const number of numbers) {
if (number < 30) {
numbersLessThan30.push(30);
}
}
// OUT [ 10, 20 ].
```
The second solution can be 10x times faster than the first.
This is a publication about a performance test based on all methods: https://hackernoon.com/javascript-performance-test-for-vs-for-each-vs-map-reduce-filter-find-32c1113f19d7.
Contributor guide
Assessment
This issue has not been assessed yet.