Diff
Modified: trunk/Source/WebCore/ChangeLog (124385 => 124386)
--- trunk/Source/WebCore/ChangeLog 2012-08-01 23:48:45 UTC (rev 124385)
+++ trunk/Source/WebCore/ChangeLog 2012-08-01 23:53:06 UTC (rev 124386)
@@ -1,3 +1,48 @@
+2012-08-01 Arnaud Renevier <[email protected]>
+
+ [V8] TypedArray binding performance improvements
+ https://bugs.webkit.org/show_bug.cgi?id=92557
+
+ Reviewed by Kenneth Russell.
+
+ Improve TypedArray bindings performance:
+ - create arrays with createUninitialized when possible. Typed Array
+ construction is about 10% faster.
+ - when creating a typed array from a same typed array, memcpy data
+ from source to target.
+
+ In order to detect if argument array is the same type as
+ implementation array, we pass the _javascript_ wrapper type as a new
+ type argument to template function constructWebGLArray.
+
+ Introduce wrapArrayBufferView which wraps typed array into a v8::Value
+
+ No new tests: Performance tests are already handled by
+ Bindings/typed-array-construct-from-same-type.html and
+ Bindings/typed-array-construct-from-typed.html
+
+ * bindings/v8/custom/V8ArrayBufferViewCustom.h:
+ (WebCore):
+ (WebCore::constructWebGLArray):
+ * bindings/v8/custom/V8Float32ArrayCustom.cpp:
+ (WebCore::V8Float32Array::constructorCallback):
+ * bindings/v8/custom/V8Float64ArrayCustom.cpp:
+ (WebCore::V8Float64Array::constructorCallback):
+ * bindings/v8/custom/V8Int16ArrayCustom.cpp:
+ (WebCore::V8Int16Array::constructorCallback):
+ * bindings/v8/custom/V8Int32ArrayCustom.cpp:
+ (WebCore::V8Int32Array::constructorCallback):
+ * bindings/v8/custom/V8Int8ArrayCustom.cpp:
+ (WebCore::V8Int8Array::constructorCallback):
+ * bindings/v8/custom/V8Uint16ArrayCustom.cpp:
+ (WebCore::V8Uint16Array::constructorCallback):
+ * bindings/v8/custom/V8Uint32ArrayCustom.cpp:
+ (WebCore::V8Uint32Array::constructorCallback):
+ * bindings/v8/custom/V8Uint8ArrayCustom.cpp:
+ (WebCore::V8Uint8Array::constructorCallback):
+ * bindings/v8/custom/V8Uint8ClampedArrayCustom.cpp:
+ (WebCore::V8Uint8ClampedArray::constructorCallback):
+
2012-08-01 Antoine Labour <[email protected]>
[chromium] Fix lost context handling on hud layer
Modified: trunk/Source/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.h (124385 => 124386)
--- trunk/Source/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.h 2012-08-01 23:48:45 UTC (rev 124385)
+++ trunk/Source/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.h 2012-08-01 23:53:06 UTC (rev 124386)
@@ -44,6 +44,18 @@
// Returns true if it succeeded, otherwise returns false.
bool copyElements(v8::Handle<v8::Object> destArray, v8::Handle<v8::Object> srcArray, uint32_t length, uint32_t offset, v8::Isolate*);
+template<class ArrayClass>
+v8::Handle<v8::Value> wrapArrayBufferView(const v8::Arguments& args, WrapperTypeInfo* type, ArrayClass array, v8::ExternalArrayType arrayType, bool hasIndexer)
+{
+ // Transform the holder into a wrapper object for the array.
+ V8DOMWrapper::setDOMWrapper(args.Holder(), type, array.get());
+ if (hasIndexer)
+ args.Holder()->SetIndexedPropertiesToExternalArrayData(array.get()->baseAddress(), arrayType, array.get()->length());
+ v8::Persistent<v8::Object> wrapper = v8::Persistent<v8::Object>::New(args.Holder());
+ wrapper.MarkIndependent();
+ V8DOMWrapper::setJSWrapperForDOMObject(array.release(), wrapper);
+ return args.Holder();
+}
// Template function used by the ArrayBufferView*Constructor callbacks.
template<class ArrayClass, class ElementType>
@@ -73,18 +85,14 @@
RefPtr<ArrayClass> array = ArrayClass::create(buf, offset, length);
if (!array)
return V8Proxy::setDOMException(INDEX_SIZE_ERR, args.GetIsolate());
- // Transform the holder into a wrapper object for the array.
- V8DOMWrapper::setDOMWrapper(args.Holder(), type, array.get());
- if (hasIndexer)
- args.Holder()->SetIndexedPropertiesToExternalArrayData(array.get()->baseAddress(), arrayType, array.get()->length());
- v8::Persistent<v8::Object> wrapper = v8::Persistent<v8::Object>::New(args.Holder());
- wrapper.MarkIndependent();
- V8DOMWrapper::setJSWrapperForDOMObject(array.release(), wrapper);
- return args.Holder();
+
+ return wrapArrayBufferView(args, type, array, arrayType, hasIndexer);
}
+static const char* notSmallEnoughSize = "ArrayBufferView size is not a small enough positive integer.";
+
// Template function used by the ArrayBufferView*Constructor callbacks.
-template<class ArrayClass, class ElementType>
+template<class ArrayClass, class _javascript_WrapperArrayType, class ElementType>
v8::Handle<v8::Value> constructWebGLArray(const v8::Arguments& args, WrapperTypeInfo* type, v8::ExternalArrayType arrayType)
{
if (!args.IsConstructCall())
@@ -104,15 +112,10 @@
// construct an empty view to avoid crashes when fetching the
// length.
RefPtr<ArrayClass> array = ArrayClass::create(0);
- // Transform the holder into a wrapper object for the array.
- V8DOMWrapper::setDOMWrapper(args.Holder(), type, array.get());
// Do not call SetIndexedPropertiesToExternalArrayData on this
// object. Not only is there no point from a performance
// perspective, but doing so causes errors in the subset() case.
- v8::Persistent<v8::Object> wrapper = v8::Persistent<v8::Object>::New(args.Holder());
- wrapper.MarkIndependent();
- V8DOMWrapper::setJSWrapperForDOMObject(array.release(), wrapper);
- return args.Holder();
+ return wrapArrayBufferView(args, type, array, arrayType, false);
}
// Supported constructors:
@@ -134,6 +137,20 @@
if (V8ArrayBuffer::HasInstance(args[0]))
return constructWebGLArrayWithArrayBufferArgument<ArrayClass, ElementType>(args, type, arrayType, true);
+ // See whether the first argument is the same type as impl. In that case,
+ // we can simply memcpy data from source to impl.
+ if (_javascript_WrapperArrayType::HasInstance(args[0])) {
+ ArrayClass* source = _javascript_WrapperArrayType::toNative(args[0]->ToObject());
+ uint32_t length = source->length();
+ RefPtr<ArrayClass> array = ArrayClass::createUninitialized(length);
+ if (!array.get())
+ return V8Proxy::throwError(V8Proxy::RangeError, notSmallEnoughSize, args.GetIsolate());
+
+ memcpy(array->baseAddress(), source->baseAddress(), length * sizeof(ElementType));
+
+ return wrapArrayBufferView(args, type, array, arrayType, true);
+ }
+
uint32_t len = 0;
v8::Handle<v8::Object> srcArray;
bool doInstantiation = false;
@@ -154,10 +171,15 @@
}
RefPtr<ArrayClass> array;
- if (doInstantiation)
- array = ArrayClass::create(len);
+ if (doInstantiation) {
+ if (srcArray.IsEmpty())
+ array = ArrayClass::create(len);
+ else
+ array = ArrayClass::createUninitialized(len);
+ }
+
if (!array.get())
- return V8Proxy::throwError(V8Proxy::RangeError, "ArrayBufferView size is not a small enough positive integer.", args.GetIsolate());
+ return V8Proxy::throwError(V8Proxy::RangeError, notSmallEnoughSize, args.GetIsolate());
// Transform the holder into a wrapper object for the array.
Modified: trunk/Source/WebCore/bindings/v8/custom/V8Float32ArrayCustom.cpp (124385 => 124386)
--- trunk/Source/WebCore/bindings/v8/custom/V8Float32ArrayCustom.cpp 2012-08-01 23:48:45 UTC (rev 124385)
+++ trunk/Source/WebCore/bindings/v8/custom/V8Float32ArrayCustom.cpp 2012-08-01 23:53:06 UTC (rev 124386)
@@ -45,7 +45,7 @@
{
INC_STATS("DOM.Float32Array.Contructor");
- return constructWebGLArray<Float32Array, float>(args, &info, v8::kExternalFloatArray);
+ return constructWebGLArray<Float32Array, V8Float32Array, float>(args, &info, v8::kExternalFloatArray);
}
v8::Handle<v8::Value> V8Float32Array::setCallback(const v8::Arguments& args)
Modified: trunk/Source/WebCore/bindings/v8/custom/V8Float64ArrayCustom.cpp (124385 => 124386)
--- trunk/Source/WebCore/bindings/v8/custom/V8Float64ArrayCustom.cpp 2012-08-01 23:48:45 UTC (rev 124385)
+++ trunk/Source/WebCore/bindings/v8/custom/V8Float64ArrayCustom.cpp 2012-08-01 23:53:06 UTC (rev 124386)
@@ -40,7 +40,7 @@
{
INC_STATS("DOM.Float64Array.Contructor");
- return constructWebGLArray<Float64Array, double>(args, &info, v8::kExternalDoubleArray);
+ return constructWebGLArray<Float64Array, V8Float64Array, double>(args, &info, v8::kExternalDoubleArray);
}
v8::Handle<v8::Value> V8Float64Array::setCallback(const v8::Arguments& args)
Modified: trunk/Source/WebCore/bindings/v8/custom/V8Int16ArrayCustom.cpp (124385 => 124386)
--- trunk/Source/WebCore/bindings/v8/custom/V8Int16ArrayCustom.cpp 2012-08-01 23:48:45 UTC (rev 124385)
+++ trunk/Source/WebCore/bindings/v8/custom/V8Int16ArrayCustom.cpp 2012-08-01 23:53:06 UTC (rev 124386)
@@ -44,7 +44,7 @@
{
INC_STATS("DOM.Int16Array.Contructor");
- return constructWebGLArray<Int16Array, short>(args, &info, v8::kExternalShortArray);
+ return constructWebGLArray<Int16Array, V8Int16Array, short>(args, &info, v8::kExternalShortArray);
}
v8::Handle<v8::Value> V8Int16Array::setCallback(const v8::Arguments& args)
Modified: trunk/Source/WebCore/bindings/v8/custom/V8Int32ArrayCustom.cpp (124385 => 124386)
--- trunk/Source/WebCore/bindings/v8/custom/V8Int32ArrayCustom.cpp 2012-08-01 23:48:45 UTC (rev 124385)
+++ trunk/Source/WebCore/bindings/v8/custom/V8Int32ArrayCustom.cpp 2012-08-01 23:53:06 UTC (rev 124386)
@@ -44,7 +44,7 @@
{
INC_STATS("DOM.Int32Array.Contructor");
- return constructWebGLArray<Int32Array, int>(args, &info, v8::kExternalIntArray);
+ return constructWebGLArray<Int32Array, V8Int32Array, int>(args, &info, v8::kExternalIntArray);
}
v8::Handle<v8::Value> V8Int32Array::setCallback(const v8::Arguments& args)
Modified: trunk/Source/WebCore/bindings/v8/custom/V8Int8ArrayCustom.cpp (124385 => 124386)
--- trunk/Source/WebCore/bindings/v8/custom/V8Int8ArrayCustom.cpp 2012-08-01 23:48:45 UTC (rev 124385)
+++ trunk/Source/WebCore/bindings/v8/custom/V8Int8ArrayCustom.cpp 2012-08-01 23:53:06 UTC (rev 124386)
@@ -44,7 +44,7 @@
{
INC_STATS("DOM.Int8Array.Contructor");
- return constructWebGLArray<Int8Array, signed char>(args, &info, v8::kExternalByteArray);
+ return constructWebGLArray<Int8Array, V8Int8Array, signed char>(args, &info, v8::kExternalByteArray);
}
v8::Handle<v8::Value> V8Int8Array::setCallback(const v8::Arguments& args)
Modified: trunk/Source/WebCore/bindings/v8/custom/V8Uint16ArrayCustom.cpp (124385 => 124386)
--- trunk/Source/WebCore/bindings/v8/custom/V8Uint16ArrayCustom.cpp 2012-08-01 23:48:45 UTC (rev 124385)
+++ trunk/Source/WebCore/bindings/v8/custom/V8Uint16ArrayCustom.cpp 2012-08-01 23:53:06 UTC (rev 124386)
@@ -44,7 +44,7 @@
{
INC_STATS("DOM.Uint16Array.Contructor");
- return constructWebGLArray<Uint16Array, unsigned short>(args, &info, v8::kExternalUnsignedShortArray);
+ return constructWebGLArray<Uint16Array, V8Uint16Array, unsigned short>(args, &info, v8::kExternalUnsignedShortArray);
}
v8::Handle<v8::Value> V8Uint16Array::setCallback(const v8::Arguments& args)
Modified: trunk/Source/WebCore/bindings/v8/custom/V8Uint32ArrayCustom.cpp (124385 => 124386)
--- trunk/Source/WebCore/bindings/v8/custom/V8Uint32ArrayCustom.cpp 2012-08-01 23:48:45 UTC (rev 124385)
+++ trunk/Source/WebCore/bindings/v8/custom/V8Uint32ArrayCustom.cpp 2012-08-01 23:53:06 UTC (rev 124386)
@@ -44,7 +44,7 @@
{
INC_STATS("DOM.Uint32Array.Contructor");
- return constructWebGLArray<Uint32Array, unsigned int>(args, &info, v8::kExternalUnsignedIntArray);
+ return constructWebGLArray<Uint32Array, V8Uint32Array, unsigned int>(args, &info, v8::kExternalUnsignedIntArray);
}
v8::Handle<v8::Value> V8Uint32Array::setCallback(const v8::Arguments& args)
Modified: trunk/Source/WebCore/bindings/v8/custom/V8Uint8ArrayCustom.cpp (124385 => 124386)
--- trunk/Source/WebCore/bindings/v8/custom/V8Uint8ArrayCustom.cpp 2012-08-01 23:48:45 UTC (rev 124385)
+++ trunk/Source/WebCore/bindings/v8/custom/V8Uint8ArrayCustom.cpp 2012-08-01 23:53:06 UTC (rev 124386)
@@ -44,7 +44,7 @@
{
INC_STATS("DOM.Uint8Array.Contructor");
- return constructWebGLArray<Uint8Array, unsigned char>(args, &info, v8::kExternalUnsignedByteArray);
+ return constructWebGLArray<Uint8Array, V8Uint8Array, unsigned char>(args, &info, v8::kExternalUnsignedByteArray);
}
v8::Handle<v8::Value> V8Uint8Array::setCallback(const v8::Arguments& args)
Modified: trunk/Source/WebCore/bindings/v8/custom/V8Uint8ClampedArrayCustom.cpp (124385 => 124386)
--- trunk/Source/WebCore/bindings/v8/custom/V8Uint8ClampedArrayCustom.cpp 2012-08-01 23:48:45 UTC (rev 124385)
+++ trunk/Source/WebCore/bindings/v8/custom/V8Uint8ClampedArrayCustom.cpp 2012-08-01 23:53:06 UTC (rev 124386)
@@ -41,7 +41,7 @@
{
INC_STATS("DOM.Uint8ClampedArray.Contructor");
- return constructWebGLArray<Uint8ClampedArray, unsigned char>(args, &info, v8::kExternalPixelArray);
+ return constructWebGLArray<Uint8ClampedArray, V8Uint8ClampedArray, unsigned char>(args, &info, v8::kExternalPixelArray);
}
v8::Handle<v8::Value> V8Uint8ClampedArray::setCallback(const v8::Arguments& args)