Skip to content

lib: performance improvement on readline async iterator

Rodrigo Muino Tomonari requested to merge github/fork/Farenheith/master into main

Using a direct approach to create the readline async iterator allowed an iteration over 20 to 58% faster.

BREAKING CHANGE: With that change, the async iteterator obtained from the readline interface doesn't have the property "stream" any longer. This happened because it's no longer created through a Readable, instead, the async iterator is created directly from the events of the readline interface instance, so, if anyone is using that property, this change will break their code. Also, the Readable added a backpressure control that is fairly compensated by the use of FixedQueue + monitoring its size. This control wasn't really precise with readline before, though, because it only pauses the reading of the original stream, but the lines generated from the last message received from it was still emitted. For example: if the readable was paused at 1000 messages but the last one received generated 10k lines, but no further messages were emitted again until the queue was lower than the readable highWaterMark. A similar behavior still happens with the new implementation, but the highWaterMark used is fixed: 1024, and the original stream is resumed again only after the queue is cleared.

Before making this change, I created a package implementing the same concept used here to validate it. You can find it here if this helps anyhow.

Merge request reports

Loading