• Benedikt Meurer's avatar
    [es2015] Optimize TypedArray.prototype[Symbol.toStringTag]. · b8b76eba
    Benedikt Meurer authored
    The TypedArray.prototype[Symbol.toStringTag] getter is currently the best (and
    as far as I can tell only definitely side-effect free) way to check whether an
    arbitrary object is a TypedArray - either generally TypedArray or a specific
    one like Uint8Array. Using the getter is thus emerging as the general pattern
    to detect TypedArrays, even Node.js now adapted it starting with
    
      https://github.com/nodejs/node/pull/15663
    
    for the isTypedArray and isUint8Array type checks in lib/internal/util/types.js
    now.
    
    The getter returns either the string with the TypedArray subclass name
    (i.e. "Uint8Array") or undefined if the receiver is not a TypedArray.
    This can be implemented with a simple elements kind dispatch, instead of
    checking the instance type and then loading the class name from the
    constructor, which requires a loop walking up the transition tree. This
    CL ports the builtin to CSA and TurboFan, and changes the logic to a
    simple elements kind check. On the micro-benchmark mentioned in the
    referenced bug, the time goes from
    
      testIsArrayBufferView: 565 ms.
      testIsTypedArray: 2403 ms.
      testIsUint8Array: 3847 ms.
    
    to
    
      testIsArrayBufferView: 566 ms.
      testIsTypedArray: 965 ms.
      testIsUint8Array: 965 ms.
    
    which presents an up to 4x improvement.
    
    Bug: v8:6874
    Change-Id: I9c330b4529d9631df2f052acf023c6a4fae69611
    Reviewed-on: https://chromium-review.googlesource.com/695021Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
    Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#48254}
    b8b76eba
Name
Last commit
Last update
benchmarks Loading commit data...
build_overrides Loading commit data...
docs Loading commit data...
gni Loading commit data...
gypfiles Loading commit data...
include Loading commit data...
infra Loading commit data...
samples Loading commit data...
src Loading commit data...
test Loading commit data...
testing Loading commit data...
third_party Loading commit data...
tools Loading commit data...
.clang-format Loading commit data...
.editorconfig Loading commit data...
.gitignore Loading commit data...
.gn Loading commit data...
.ycm_extra_conf.py Loading commit data...
AUTHORS Loading commit data...
BUILD.gn Loading commit data...
CODE_OF_CONDUCT.md Loading commit data...
ChangeLog Loading commit data...
DEPS Loading commit data...
LICENSE Loading commit data...
LICENSE.fdlibm Loading commit data...
LICENSE.strongtalk Loading commit data...
LICENSE.v8 Loading commit data...
LICENSE.valgrind Loading commit data...
Makefile Loading commit data...
Makefile.android Loading commit data...
OWNERS Loading commit data...
PRESUBMIT.py Loading commit data...
README.md Loading commit data...
WATCHLISTS Loading commit data...
codereview.settings Loading commit data...
snapshot_toolchain.gni Loading commit data...