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

perf: avoid excessive linear scanning for large functions #1399

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Commits on May 20, 2024

  1. perf: avoid excessive linear scanning for large functions

    This commit restores the token indices for a node after they have been refined
    to span the node, instead of before the refinement. This avoids the potential for
    excessive searches for token indices, which is implemented using a linear scan.
    
    It was attempted to convert the linear scans into binary searches (which an
    accompanying comment on `findTokenRange` indicates shouldn't be needed) and that
    also avoids the problem, but using the refined positions as implemented in this
    commit is even more effective, to the point where using a binary search is less
    efficient in my testing.
    
    This change can achieve a substantial improvement, where an ~2.6MB file used to be
    parsed and cloned in ~120s, now reduced to ~1.5s, almost two orders of magnitude
    faster.
    
    The perf test that tests the `backbone.js` file shows that performance improves
    from ~60ms to ~53ms, only a slight improvement.
    JoostK committed May 20, 2024
    Configuration menu
    Copy the full SHA
    2742c16 View commit details
    Browse the repository at this point in the history
  2. perf: micro optimizations for node cloning

    This commit makes various micro optimizations to improve node cloning performance.
    
    In particular, `Object.create` with property descriptors appears to be slower than
    `Object.defineProperty` after the object has been created (measured in Node 18 and 20).
    
    The other bigger factor was the early bailout in `TCp.copy` for non-object values, as
    such primitives will never hit any of the remaining logic.
    
    For a 2.6MB large file, this improves parsing and cloning times from ~1.5s to ~1.2s.
    The performance test using `backbone.js` sess about 10% improvement.
    JoostK committed May 20, 2024
    Configuration menu
    Copy the full SHA
    8f73d07 View commit details
    Browse the repository at this point in the history