-
-
Notifications
You must be signed in to change notification settings - Fork 35k
Description
- Version: v12.1.0
- Platform: Windows 10 64-bit
Some background: I recently read an old article that, among other things, looked at performance in Node (6 at the time) for map/reduce vs using a for loop, and after seeing a comment by someone else about the recent performance changes in later version of V8, decided to see if there was any difference in the results in later version of Node. So I set out to try and reproduce their test and results, and started looking at newer versions of Node to compare, and ended up stumbling upon what appears to be a rather significant performance regression.
The test is fairly simple, take a list of 32 million random numbers, and calculate the sum of the squares. The full code for the test I ran can be found here: https://gist.github.com/kbjr/1a551ddb3b59e9685b04bb051daef44c
But the two basic samples are this:
const result = data
.map((x) => x ** 2)
.reduce((memo, x) => memo + x, 0);let result = 0;
for (let i = 0; i < data.length; i++) {
result += data[i] ** 2;
}The for loop version is faster, but that has always been the case and is not the point of this issue. Here are the results I got from running this test on 10.15.0:
runMapReduce 12602.4ms 13285.9ms 12729.4ms
runForEach 2407.41ms 2358.85ms 2432.26ms
runForLoop 69.4525ms 47.4004ms 56.8418ms
runForLoopNoLength 66.4152ms 51.5009ms 55.3084ms
Which looks about the same as the original results in the article I had read, so I wasn't really surprised at the outcome. What did surprise me was when I ran the test again on 12.1.0:
runMapReduce 126262ms 126607ms 129501ms
runForEach 1451.66ms 1457.29ms 1490.63ms
runForLoop 38.9766ms 45.9452ms 34.7133ms
runForLoopNoLength 38.9530ms 44.0065ms 35.1938ms
The other tests actually all got some small speed ups, but the map/reduce slowed down by basically a whole order of magnitude.