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

errors: improve error creation performance #46648

Closed
wants to merge 15 commits into from

Commits on Mar 2, 2023

  1. errors: improve hideInternalStackFrames performance

    Directly concat the necessary information to a string instead of
    allocating intermediate arrays and iterating over the array more
    than once.
    
    Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de>
    BridgeAR committed Mar 2, 2023
    Configuration menu
    Copy the full SHA
    ed1a664 View commit details
    Browse the repository at this point in the history
  2. errors: reuse addNumericSeparator from internal inspect

    Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de>
    BridgeAR committed Mar 2, 2023
    Configuration menu
    Copy the full SHA
    d21f72b View commit details
    Browse the repository at this point in the history
  3. lib: make sure internal assertions use internal/assert

    The assert module should only be used by users, not by Node.js
    internally.
    
    Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de>
    BridgeAR committed Mar 2, 2023
    Configuration menu
    Copy the full SHA
    b287852 View commit details
    Browse the repository at this point in the history
  4. net: reuse existing aggregateTwoErrors functionality

    Instead of providing a similar functionality, just reuse the other
    method.
    
    Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de>
    BridgeAR committed Mar 2, 2023
    Configuration menu
    Copy the full SHA
    c4f3517 View commit details
    Browse the repository at this point in the history
  5. errors: minor performance improvement

    The arguments check is moved to the error class setup time instead
    of error instance creation time.
    
    Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de>
    BridgeAR committed Mar 2, 2023
    Configuration menu
    Copy the full SHA
    0d72d40 View commit details
    Browse the repository at this point in the history
  6. errors: improve NodeError creation performance

    This improves the performance by removing the extra stack trace
    collection step. Instead, just change the maximum stack trace limit
    to the current limit plus 25.
    The arbitrary 25 is used as arbitrary upper bound to prevent huge
    overhead in recursive methods. The limit should normally not be
    reached and should therefore suffice.
    
    Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de>
    BridgeAR committed Mar 2, 2023
    Configuration menu
    Copy the full SHA
    2d8a4a3 View commit details
    Browse the repository at this point in the history
  7. errors: do not remove already collected stack frames in NodeErrors

    Currently, already collected user stack frames are removed during
    stack frame serialization to adhere to the defined maximum stack
    frame limit. This limit is mainly there to prevent extra cpu
    overhead while gathering the stack frames. Removing stack frames
    after already collecting them won't improve the performance and
    only limit the debuggability for users later.
    
    Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de>
    BridgeAR committed Mar 2, 2023
    Configuration menu
    Copy the full SHA
    69df124 View commit details
    Browse the repository at this point in the history
  8. errors: format more numbers with numeric separator

    This simplifies the implementation of the OUT_OF_RANGE error by
    reusing the current inspect functionality.
    
    Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de>
    BridgeAR committed Mar 2, 2023
    Configuration menu
    Copy the full SHA
    4ddd43f View commit details
    Browse the repository at this point in the history
  9. errors: improve NodeError creation performance

    The former implementation over allocated stack frames during error
    creation to substitute for internal frames that should be hidden
    to the user. This could have caused a significant performance
    overhead in deeply nested code.
    
    As side effect also simplify the setting of stackTraceLimits and
    improve the error related benchmarks.
    
    Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de>
    BridgeAR committed Mar 2, 2023
    Configuration menu
    Copy the full SHA
    087b0bc View commit details
    Browse the repository at this point in the history
  10. lib: add new to construct errors

    This makes sure all error instances use `new` to call the
    constructor.
    
    Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de>
    BridgeAR committed Mar 2, 2023
    Configuration menu
    Copy the full SHA
    6ec603c View commit details
    Browse the repository at this point in the history
  11. errors: significantly improve NodeError creation performance

    The improvement comes from the following changes:
    
    1. Less properties are defined on the error instances, especially
       no Symbol.
    2. The check if something is a NodeError or not is not needed
       anymore.
    3. The setup of NodeError now makes sure that all heavy lifting is
       done up front instead of doing that during instance creation.
    
    To align with the WPT tests, the NodeErrors must have their
    constructor set to their base class. This was not the case for
    SystemErrors and is now aligned.
    
    Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de>
    BridgeAR committed Mar 2, 2023
    Configuration menu
    Copy the full SHA
    08e1c89 View commit details
    Browse the repository at this point in the history
  12. test_runner: set the properties inside of the error method

    This improves the error recreation performance due to limiting the
    stack trace that is generated and it makes sure NodeErrors only set
    properties inside of the actual error method.
    
    Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de>
    BridgeAR committed Mar 2, 2023
    Configuration menu
    Copy the full SHA
    b3aa706 View commit details
    Browse the repository at this point in the history
  13. errors,repl: align prepareStackTrace behavior

    This fixes the issue that multiple prepareStackTrace functions
    existed that had to duplicate code in multiple spots. Instead, the
    diverging part is now replaced during runtime. This reduces the
    code overhead and makes sure there is no duplication.
    
    It also fixes the issue that `overrideStackTrace` usage would not
    adhere to the `hideStackFrame` calls. Frames are now removed before
    passing them to the override method.
    
    A second fix is for the repl: the stack frames passed to a user
    defined Error.prepareStackTrace() method are now in the correct
    order.
    As drive-by it also improves the performance for repl errors
    marginally.
    
    Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de>
    BridgeAR committed Mar 2, 2023
    Configuration menu
    Copy the full SHA
    72f87e9 View commit details
    Browse the repository at this point in the history
  14. errors: remove unused ERR_INVALID_RETURN_PROPERTY error

    Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de>
    BridgeAR committed Mar 2, 2023
    Configuration menu
    Copy the full SHA
    ee8e40f View commit details
    Browse the repository at this point in the history
  15. errors: faster ERR_MODULE_NOT_FOUND error

    The function calls are more expensive than using the error printf
    format style.
    
    Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de>
    BridgeAR committed Mar 2, 2023
    Configuration menu
    Copy the full SHA
    40ab9c3 View commit details
    Browse the repository at this point in the history