This is exactly right! When I run a synchronous version of the iterator, I can process ~65MB/s. That’s still 1/3 the speed of the equivalent Python, but it’s in the ballpark. And the speed difference may be due to the way that TypeScript downlevels generators.
let numLines = 0, numBytes = 0;
for (const line of linesSync('stop_times.txt')) {
numLines++;
numBytes += line.length;
}
console.log(`Read ${numLines} lines, ${numBytes} bytes.`);
Thinking a little more about this, one thing I’ve learned from this post and the responses to it is that a knee-jerk “sync is bad” reaction isn’t always appropriate. If a server needs to read a huge CSV before serving requests, it may as well do so synchronously (and quickly).
This post prompted a discussion on the TC39 proposal GitHub. The gist is that they don’t think the semantics are broken, just that for-await-of should be much than it is. It’s hard to argue with that. If the simple for-await-of loop were as fast as the for-of equivalent, that would be the best of both worlds.