Skip to content
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

lib: performance improvement on readline async iterator #41276

Merged
merged 25 commits into from
Oct 24, 2022

Commits on Oct 18, 2022

  1. lib: performance improvement on readline async iterator

    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 that change, I created a package implementing
    the same concept used here to validate it. You can find it
    [here](https://github.com/Farenheith/faster-readline-iterator)
    if this helps anyhow.
    Thiago Santos authored and Farenheith committed Oct 18, 2022
    Configuration menu
    Copy the full SHA
    c467ffe View commit details
    Browse the repository at this point in the history
  2. lib: undoing accidental changes

    Some Changes I just sent wasn't related to the PR in question,
    so I'm undoing then (in events.js and the addition of linkedMap.js)
    Also, fixed the [SymbolAsyncIterator] function returned by
    eventsToAsyncIteratorFactory, that was referencing a no longer
    available variable
    Farenheith committed Oct 18, 2022
    Configuration menu
    Copy the full SHA
    05db8ff View commit details
    Browse the repository at this point in the history
  3. lib: changing once to on in waitNext

    After seeing how once method works on EventEmitter,
    it was clear that it doesn't make sense to use it
    into the waitNext method, as the callback
    will already remove the events
    Farenheith committed Oct 18, 2022
    Configuration menu
    Copy the full SHA
    3ecee3c View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    83919d2 View commit details
    Browse the repository at this point in the history
  5. lib: adding different lines multiplier

    Adding different lines multipliers is good for this bench
    because we can see how well the change performs in
    different scales. That way we can find out if there some
    curve with some point where the benefits starts or ends
    Farenheith committed Oct 18, 2022
    Configuration menu
    Copy the full SHA
    03ac26d View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    870b5cf View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    ae3325c View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    bb6f6ab View commit details
    Browse the repository at this point in the history
  9. lib: performance improvement on readline async iterator

    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 that change, I created a package implementing
    the same concept used here to validate it. You can find it
    [here](https://github.com/Farenheith/faster-readline-iterator)
    if this helps anyhow.
    Thiago Santos authored and Farenheith committed Oct 18, 2022
    Configuration menu
    Copy the full SHA
    221e239 View commit details
    Browse the repository at this point in the history
  10. lib: undoing accidental changes

    Some Changes I just sent wasn't related to the PR in question,
    so I'm undoing then (in events.js and the addition of linkedMap.js)
    Also, fixed the [SymbolAsyncIterator] function returned by
    eventsToAsyncIteratorFactory, that was referencing a no longer
    available variable
    Farenheith committed Oct 18, 2022
    Configuration menu
    Copy the full SHA
    b536144 View commit details
    Browse the repository at this point in the history
  11. lib: changing once to on in waitNext

    After seeing how once method works on EventEmitter,
    it was clear that it doesn't make sense to use it
    into the waitNext method, as the callback
    will already remove the events
    Farenheith committed Oct 18, 2022
    Configuration menu
    Copy the full SHA
    31efb2d View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    0e04a18 View commit details
    Browse the repository at this point in the history
  13. Configuration menu
    Copy the full SHA
    7a8c3fa View commit details
    Browse the repository at this point in the history
  14. Configuration menu
    Copy the full SHA
    156837b View commit details
    Browse the repository at this point in the history
  15. Configuration menu
    Copy the full SHA
    87da1a2 View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    e7f358a View commit details
    Browse the repository at this point in the history
  17. Configuration menu
    Copy the full SHA
    d5917c9 View commit details
    Browse the repository at this point in the history
  18. Configuration menu
    Copy the full SHA
    0143cdf View commit details
    Browse the repository at this point in the history
  19. Configuration menu
    Copy the full SHA
    917c51b View commit details
    Browse the repository at this point in the history
  20. Configuration menu
    Copy the full SHA
    4e8be80 View commit details
    Browse the repository at this point in the history
  21. refactor: Apply suggestions from code review

    Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
    Farenheith and aduh95 committed Oct 18, 2022
    Configuration menu
    Copy the full SHA
    610a275 View commit details
    Browse the repository at this point in the history
  22. Configuration menu
    Copy the full SHA
    e1dd9d3 View commit details
    Browse the repository at this point in the history
  23. Configuration menu
    Copy the full SHA
    26d066b View commit details
    Browse the repository at this point in the history
  24. Configuration menu
    Copy the full SHA
    835bb5f View commit details
    Browse the repository at this point in the history
  25. Configuration menu
    Copy the full SHA
    e83baea View commit details
    Browse the repository at this point in the history