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: faster event listening #41309

Closed

Commits on Dec 24, 2021

  1. lib: faster event listening

    The current EventEmitter uses arrays to control multiple listeners,
    but that means that prependListener and removeListeners operations
    have an O(N) time complexity. With this change, instead of an array
    we use a map + a linked list (to preserve execution order), which
    gives an O(1) time complexity for those operations. This will be
    especially helpful in scenarios where we have many listeners to
    the same event.
    
    BREAKING CHANGE: I don't know how much this is a breaking change,
    because if someone is using the _events property, I think it is bad
    usage that has no guarantees to keep working. Regardless, the _events
    property will no longer be a function or an array, but a function
    or a "MappedLinkedList". Some of the operations from the array are
    present, though, like [Symbol.iterator], unshift and push, making
    it possible to adapt some code that is arbritary using it
    Farenheith committed Dec 24, 2021
    Configuration menu
    Copy the full SHA
    eb49f16 View commit details
    Browse the repository at this point in the history
  2. lib: changing shift to pop during remove method

    To make sure the removing of method follows a LIFO logic
    when the same listener is added twice, it's important to
    do a pop instead of a shift operation
    Farenheith committed Dec 24, 2021
    Configuration menu
    Copy the full SHA
    9b769a3 View commit details
    Browse the repository at this point in the history