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

Avoid reading outside of collection bounds #3769

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Commits on Aug 29, 2017

  1. Avoid reading outside of collection bounds

    Consider the following collection:
    
        const array = ['a', 'b', 'c'];
    
    Retrieving `array[0]` can be done relatively quickly. However, when the property doesn’t exist on the receiver, JavaScript engines must continue to look up the prototype chain until either the property is found or the chain ends. This is inherently slower than *not* doing any prototype chain lookups. Retrieving an out-of-bounds index, e.g. `array[3]`, triggers this scenario, resulting in decreased performance.
    
    This patch changes the way some loops are written to avoid running into the slow case unnecessarily.
    
    A more in-depth explanation featuring a jQuery-specific example can be found here: https://ripsawridge.github.io/articles/blink-mysterium/
    mathiasbynens committed Aug 29, 2017
    Configuration menu
    Copy the full SHA
    9d8431c View commit details
    Browse the repository at this point in the history