Skip to content
Permalink
Browse files
[V8] REGRESSION(94783): calling the binding script during V8 context …
…creation slows down page loads

https://bugs.webkit.org/show_bug.cgi?id=68237

Patch by Ulan Degenbaev <ulan@chromium.org> on 2011-09-16
Reviewed by Kenneth Russell.

Call the binding script lazily on the first run of the set() method of
a typed array.

* ../../Source/WebCore/WebCore.gypi:
* ../../Source/WebCore/bindings/v8/V8BindingScripts.cpp: Removed.
* ../../Source/WebCore/bindings/v8/V8BindingScripts.h: Removed.
* ../../Source/WebCore/bindings/v8/V8DOMWindowShell.cpp:
* ../../Source/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp:
* ../../Source/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.cpp:
* ../../Source/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.h:
* ../../Source/WebCore/bindings/v8/custom/V8ArrayBufferViewCustomScript.js:

Canonical link: https://commits.webkit.org/84223@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@95354 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
ulan authored and webkit-commit-queue committed Sep 17, 2011
1 parent 3f91b60 commit b9a4b6a5635aa046293fa97891c377998e14fcee
Showing 9 changed files with 67 additions and 97 deletions.
@@ -1,3 +1,22 @@
2011-09-16 Ulan Degenbaev <ulan@chromium.org>

[V8] REGRESSION(94783): calling the binding script during V8 context creation slows down page loads
https://bugs.webkit.org/show_bug.cgi?id=68237

Reviewed by Kenneth Russell.

Call the binding script lazily on the first run of the set() method of
a typed array.

* ../../Source/WebCore/WebCore.gypi:
* ../../Source/WebCore/bindings/v8/V8BindingScripts.cpp: Removed.
* ../../Source/WebCore/bindings/v8/V8BindingScripts.h: Removed.
* ../../Source/WebCore/bindings/v8/V8DOMWindowShell.cpp:
* ../../Source/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp:
* ../../Source/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.cpp:
* ../../Source/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.h:
* ../../Source/WebCore/bindings/v8/custom/V8ArrayBufferViewCustomScript.js:

2011-09-16 Martin Robinson <mrobinson@igalia.com>

[GTK] Disable WebKit2 by default in configure.ac, but enable it with build-webkit
@@ -2063,8 +2063,6 @@
'bindings/v8/V8AbstractEventListener.h',
'bindings/v8/V8Binding.cpp',
'bindings/v8/V8Binding.h',
'bindings/v8/V8BindingScripts.cpp',
'bindings/v8/V8BindingScripts.h',
'bindings/v8/V8Collection.cpp',
'bindings/v8/V8Collection.h',
'bindings/v8/V8DOMMap.cpp',

This file was deleted.

This file was deleted.

@@ -46,7 +46,6 @@
#include "SecurityOrigin.h"
#include "StorageNamespace.h"
#include "V8Binding.h"
#include "V8BindingScripts.h"
#include "V8BindingState.h"
#include "V8Collection.h"
#include "V8DOMMap.h"
@@ -340,8 +339,6 @@ bool V8DOMWindowShell::initContextIfNeeded()

setSecurityToken();

V8BindingScripts::runScripts(v8Context);

m_frame->loader()->client()->didCreateScriptContextForFrame();

// FIXME: This is wrong. We should actually do this for the proper world once
@@ -41,7 +41,6 @@
#include "SharedWorker.h"
#include "SharedWorkerContext.h"
#include "V8Binding.h"
#include "V8BindingScripts.h"
#include "V8DOMMap.h"
#include "V8DedicatedWorkerContext.h"
#include "V8Proxy.h"
@@ -176,8 +175,6 @@ bool WorkerContextExecutionProxy::initContextIfNeeded()
v8::Handle<v8::Object> globalObject = v8::Handle<v8::Object>::Cast(m_context->Global()->GetPrototype());
globalObject->SetPrototype(jsWorkerContext);

V8BindingScripts::runScripts(context);

return true;
}

@@ -26,10 +26,39 @@
#include "config.h"
#include "V8ArrayBufferViewCustom.h"

#include "V8ArrayBufferViewCustomScript.h"
#include <v8.h>


namespace WebCore {

const char fastSetFlagName[] = "webgl::FastSetFlag";

bool fastSetInstalled(v8::Handle<v8::Object> array)
{
// Use a hidden flag in the common prototype (ArrayBufferView) of all typed
// arrays as an indicator of whether the fast 'set' is installed or not.
v8::Handle<v8::Object> prototype = array->GetPrototype().As<v8::Object>();
v8::Handle<v8::Object> arrayBufferView = prototype->GetPrototype().As<v8::Object>();
v8::Handle<v8::String> key = v8::String::New(fastSetFlagName);
v8::Handle<v8::Value> fastSetFlag = arrayBufferView->GetHiddenValue(key);
return !fastSetFlag.IsEmpty();
}

void installFastSet(v8::Handle<v8::Object> array)
{
v8::Handle<v8::Object> prototype = array->GetPrototype().As<v8::Object>();
v8::Handle<v8::Object> arrayBufferView = prototype->GetPrototype().As<v8::Object>();
v8::Handle<v8::String> key = v8::String::New(fastSetFlagName);
arrayBufferView->SetHiddenValue(key, v8::Boolean::New(true));

String source(reinterpret_cast<const char*>(V8ArrayBufferViewCustomScript_js),
sizeof(V8ArrayBufferViewCustomScript_js));
v8::Handle<v8::Script> script = v8::Script::Compile(v8String(source));
script->Run();
}


void copyElements(v8::Handle<v8::Object> destArray, v8::Handle<v8::Object> srcArray)
{
v8::Handle<v8::String> key = v8::String::New("set");
@@ -41,10 +41,19 @@
namespace WebCore {


// Check if the JavaScript 'set' method was already installed
// on the prototype of the given typed array.
bool fastSetInstalled(v8::Handle<v8::Object> array);

// Install the JavaScript 'set' method on the prototype of
// the given typed array.
void installFastSet(v8::Handle<v8::Object> array);

// Copy the elements from the source array to the typed destination array by
// invoking the 'set' method of the destination array in JS.
void copyElements(v8::Handle<v8::Object> destArray, v8::Handle<v8::Object> srcArray);


// Template function used by the ArrayBufferView*Constructor callbacks.
template<class ArrayClass, class ElementType>
v8::Handle<v8::Value> constructWebGLArrayWithArrayBufferArgument(const v8::Arguments& args, WrapperTypeInfo* type, v8::ExternalArrayType arrayType, bool hasIndexer)
@@ -198,10 +207,15 @@ v8::Handle<v8::Value> setWebGLArrayHelper(const v8::Arguments& args)
|| offset + length < offset)
// Out of range offset or overflow
V8Proxy::setDOMException(INDEX_SIZE_ERR);
else
for (uint32_t i = 0; i < length; i++)
impl->set(offset + i, array->Get(i)->NumberValue());

else {
if (!fastSetInstalled(args.Holder())) {
installFastSet(args.Holder());
copyElements(args.Holder(), array);
} else {
for (uint32_t i = 0; i < length; i++)
impl->set(offset + i, array->Get(i)->NumberValue());
}
}
return v8::Undefined();
}

@@ -41,6 +41,7 @@ var optimizeSetMethod = function(type)
} else
return nativeSet.call(this, source, offset);
}
f.name = "set";
return f;
})();
};

0 comments on commit b9a4b6a

Please sign in to comment.