Commit aadf2de8 authored by eric@webkit.org's avatar eric@webkit.org

2010-06-04 Tony Gentilcore <tonyg@chromium.org>

        Reviewed by Adam Barth.

        Persist V8's ScriptData to the memory cache.
        https://bugs.webkit.org/show_bug.cgi?id=38661

        This stores V8's ScriptData in the memory cache and also causes the
        network platform layer to be notified of the available cacheable
        metadata.

        Chromium's morejs benchmark shows a 3-4% improvement on fast hardware.

        No new tests because no new functionality.

        * bindings/v8/ScriptSourceCode.h:
        (WebCore::ScriptSourceCode::ScriptSourceCode):
        (WebCore::ScriptSourceCode::cachedScript):
        * bindings/v8/V8Proxy.cpp:
        (WebCore::V8Proxy::compileScript):
        (WebCore::V8Proxy::precompileScript):
        (WebCore::V8Proxy::evaluate):
        * bindings/v8/V8Proxy.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@60684 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 2a276abe
2010-06-04 Tony Gentilcore <tonyg@chromium.org>
Reviewed by Adam Barth.
Persist V8's ScriptData to the memory cache.
https://bugs.webkit.org/show_bug.cgi?id=38661
This stores V8's ScriptData in the memory cache and also causes the
network platform layer to be notified of the available cacheable
metadata.
Chromium's morejs benchmark shows a 3-4% improvement on fast hardware.
No new tests because no new functionality.
* bindings/v8/ScriptSourceCode.h:
(WebCore::ScriptSourceCode::ScriptSourceCode):
(WebCore::ScriptSourceCode::cachedScript):
* bindings/v8/V8Proxy.cpp:
(WebCore::V8Proxy::compileScript):
(WebCore::V8Proxy::precompileScript):
(WebCore::V8Proxy::evaluate):
* bindings/v8/V8Proxy.h:
2010-06-04 Tony Gentilcore <tonyg@chromium.org>
Reviewed by Adam Barth.
......
......@@ -31,6 +31,7 @@
#ifndef ScriptSourceCode_h
#define ScriptSourceCode_h
#include "CachedResourceHandle.h"
#include "CachedScript.h"
#include "KURL.h"
#include "PlatformString.h"
......@@ -41,6 +42,7 @@ class ScriptSourceCode {
public:
ScriptSourceCode(const String& source, const KURL& url = KURL(), int startLine = 1)
: m_source(source)
, m_cachedScript(0)
, m_url(url)
, m_startLine(startLine)
{
......@@ -50,6 +52,7 @@ public:
// Not sure if that matters.
ScriptSourceCode(CachedScript* cs)
: m_source(cs->script())
, m_cachedScript(cs)
, m_url(ParsedURLString, cs->url())
, m_startLine(1)
{
......@@ -58,11 +61,13 @@ public:
bool isEmpty() const { return m_source.isEmpty(); }
const String& source() const { return m_source; }
CachedScript* cachedScript() const { return m_cachedScript.get(); }
const KURL& url() const { return m_url; }
int startLine() const { return m_startLine; }
private:
String m_source;
CachedResourceHandle<CachedScript> m_cachedScript;
KURL m_url;
int m_startLine;
};
......
......@@ -31,6 +31,7 @@
#include "config.h"
#include "V8Proxy.h"
#include "CachedMetadata.h"
#include "CSSMutableStyleDeclaration.h"
#include "DateExtension.h"
#include "DocumentLoader.h"
......@@ -70,6 +71,7 @@
#include <v8.h>
#include <wtf/Assertions.h>
#include <wtf/OwnArrayPtr.h>
#include <wtf/OwnPtr.h>
#include <wtf/StdLibExtras.h>
#include <wtf/StringExtras.h>
#include <wtf/UnusedParam.h>
......@@ -233,13 +235,13 @@ V8Proxy::~V8Proxy()
windowShell()->destroyGlobal();
}
v8::Handle<v8::Script> V8Proxy::compileScript(v8::Handle<v8::String> code, const String& fileName, int baseLine)
v8::Handle<v8::Script> V8Proxy::compileScript(v8::Handle<v8::String> code, const String& fileName, int baseLine, v8::ScriptData* scriptData)
{
const uint16_t* fileNameString = fromWebCoreString(fileName);
v8::Handle<v8::String> name = v8::String::New(fileNameString, fileName.length());
v8::Handle<v8::Integer> line = v8::Integer::New(baseLine);
v8::ScriptOrigin origin(name, line);
v8::Handle<v8::Script> script = v8::Script::Compile(code, &origin);
v8::Handle<v8::Script> script = v8::Script::Compile(code, &origin, scriptData);
return script;
}
......@@ -338,6 +340,33 @@ bool V8Proxy::setInjectedScriptContextDebugId(v8::Handle<v8::Context> targetCont
return true;
}
PassOwnPtr<v8::ScriptData> V8Proxy::precompileScript(const ScriptSourceCode& source)
{
// A pseudo-randomly chosen ID used to store and retrieve V8 ScriptData from
// the CachedScript. If the format changes, this ID should be changed too.
static const unsigned dataTypeID = 0xECC13BD7;
// Very small scripts are not worth the effort to preparse.
static const unsigned minPreparseLength = 1024;
CachedScript* cachedScript = source.cachedScript();
if (!cachedScript)
return 0;
CachedMetadata* cachedMetadata = cachedScript->cachedMetadata(dataTypeID);
if (cachedMetadata)
return v8::ScriptData::New(cachedMetadata->data(), cachedMetadata->size());
const CString& utf8Source = source.source().utf8();
if (utf8Source.length() < minPreparseLength)
return 0;
v8::ScriptData* scriptData = v8::ScriptData::PreCompile(utf8Source.data(), utf8Source.length());
cachedScript->setCachedMetadata(dataTypeID, scriptData->Data(), scriptData->Length());
return scriptData;
}
v8::Local<v8::Value> V8Proxy::evaluate(const ScriptSourceCode& source, Node* node)
{
ASSERT(v8::Context::InContext());
......@@ -363,10 +392,11 @@ v8::Local<v8::Value> V8Proxy::evaluate(const ScriptSourceCode& source, Node* nod
#if PLATFORM(CHROMIUM)
PlatformBridge::traceEventBegin("v8.compile", node, "");
#endif
OwnPtr<v8::ScriptData> scriptData = precompileScript(source);
// NOTE: For compatibility with WebCore, ScriptSourceCode's line starts at
// 1, whereas v8 starts at 0.
v8::Handle<v8::Script> script = compileScript(code, source.url(), source.startLine() - 1);
v8::Handle<v8::Script> script = compileScript(code, source.url(), source.startLine() - 1, scriptData.get());
#if PLATFORM(CHROMIUM)
PlatformBridge::traceEventEnd("v8.compile", node, "");
......
......@@ -285,7 +285,7 @@ namespace WebCore {
static v8::Handle<v8::Value> checkNewLegal(const v8::Arguments&);
static v8::Handle<v8::Script> compileScript(v8::Handle<v8::String> code, const String& fileName, int baseLine);
static v8::Handle<v8::Script> compileScript(v8::Handle<v8::String> code, const String& fileName, int baseLine, v8::ScriptData* scriptData = 0);
// If the exception code is different from zero, a DOM exception is
// schedule to be thrown.
......@@ -337,6 +337,8 @@ namespace WebCore {
void resetIsolatedWorlds();
PassOwnPtr<v8::ScriptData> precompileScript(const ScriptSourceCode& source);
// Returns false when we're out of memory in V8.
bool setInjectedScriptContextDebugId(v8::Handle<v8::Context> targetContext);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment