⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 285971 in webkit


Ignore:
Timestamp:
Nov 17, 2021, 6:47:45 PM (5 years ago)
Author:
sbarati@apple.com
Message:

Run the memmove fast path in JSGenericTypedArrayView<Adaptor>::set when using a combination of Uint8 and Uint8Clamped
https://bugs.webkit.org/show_bug.cgi?id=233271
<rdar://85259288>

Reviewed by Yusuke Suzuki.

JSTests:

  • microbenchmarks/typed-array-set-uint8-and-uint8clamped.js: Added.

Source/JavaScriptCore:

We have a fast path for running memmove when both the thing being
copied from and the thing being copied to have the same typed array
type. However, when copying from a Uint8Array into a Uint8ClampedArray,
or vice versa, we were going down the slow path. In this case,
we can still take the fast path, since we're guaranteed that storing
into a Uint8ClampedArray from a Uint8Array will never actually need
to clamp values. And when storing from a Uint8ClampedArray into a
Uint8Array, the values can trivially be copied over.

This patch is a 100x speedup on the attached microbenchmark.

  • runtime/JSGenericTypedArrayViewInlines.h:

(JSC::JSGenericTypedArrayView<Adaptor>::set):

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r285850 r285971  
     12021-11-17  Saam Barati  <sbarati@apple.com>
     2
     3        Run the memmove fast path in JSGenericTypedArrayView<Adaptor>::set when using a combination of Uint8 and Uint8Clamped
     4        https://bugs.webkit.org/show_bug.cgi?id=233271
     5        <rdar://85259288>
     6
     7        Reviewed by Yusuke Suzuki.
     8
     9        * microbenchmarks/typed-array-set-uint8-and-uint8clamped.js: Added.
     10
    1112021-11-15  Yusuke Suzuki  <ysuzuki@apple.com>
    212
  • trunk/Source/JavaScriptCore/ChangeLog

    r285955 r285971  
     12021-11-17  Saam Barati  <sbarati@apple.com>
     2
     3        Run the memmove fast path in JSGenericTypedArrayView<Adaptor>::set when using a combination of Uint8 and Uint8Clamped
     4        https://bugs.webkit.org/show_bug.cgi?id=233271
     5        <rdar://85259288>
     6
     7        Reviewed by Yusuke Suzuki.
     8
     9        We have a fast path for running memmove when both the thing being
     10        copied from and the thing being copied to have the same typed array
     11        type. However, when copying from a Uint8Array into a Uint8ClampedArray,
     12        or vice versa, we were going down the slow path. In this case,
     13        we can still take the fast path, since we're guaranteed that storing
     14        into a Uint8ClampedArray from a Uint8Array will never actually need
     15        to clamp values. And when storing from a Uint8ClampedArray into a
     16        Uint8Array, the values can trivially be copied over.
     17
     18        This patch is a 100x speedup on the attached microbenchmark.
     19
     20        * runtime/JSGenericTypedArrayViewInlines.h:
     21        (JSC::JSGenericTypedArrayView<Adaptor>::set):
     22
    1232021-11-17  Yusuke Suzuki  <ysuzuki@apple.com>
    224
  • trunk/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewInlines.h

    r285730 r285971  
    256256    auto scope = DECLARE_THROW_SCOPE(vm);
    257257
    258     const ClassInfo* ci = object->classInfo(vm);
    259     if (ci->typedArrayStorageType == Adaptor::typeValue) {
    260         // The super fast case: we can just memmove since we're the same type.
    261         JSGenericTypedArrayView* other = jsCast<JSGenericTypedArrayView*>(object);
     258    auto memmoveFastPath = [&] (auto* other) {
     259        // The super fast case: we can just memmove since we're the same underlying storage type.
    262260        length = std::min(length, other->length());
    263261       
     
    268266            return false;
    269267
     268        RELEASE_ASSERT((std::is_same_v<decltype(typedVector()), decltype(other->typedVector())>));
    270269        memmove(typedVector() + offset, other->typedVector() + objectOffset, length * elementSize);
    271270        return true;
     271    };
     272
     273    const ClassInfo* ci = object->classInfo(vm);
     274    if (ci->typedArrayStorageType == Adaptor::typeValue)
     275        return memmoveFastPath(jsCast<JSGenericTypedArrayView*>(object));
     276
     277    auto isSomeUint8 = [] (TypedArrayType type) {
     278        return type == TypedArrayType::TypeUint8 || type == TypedArrayType::TypeUint8Clamped;
     279    };
     280    if (isSomeUint8(ci->typedArrayStorageType) && isSomeUint8(Adaptor::typeValue)) {
     281        if (ci->typedArrayStorageType == TypedArrayType::TypeUint8)
     282            return memmoveFastPath(jsCast<JSGenericTypedArrayView<Uint8Adaptor>*>(object));
     283        return memmoveFastPath(jsCast<JSGenericTypedArrayView<Uint8ClampedAdaptor>*>(object));
    272284    }
    273285   
Note: See TracChangeset for help on using the changeset viewer.